mirror of
https://github.com/urbit/shrub.git
synced 2025-01-05 19:46:50 +03:00
implements EMSA-PKCS1-v1_5 for RSA signatures
finally compatible with openssl!
This commit is contained in:
parent
aefb6dff4d
commit
dce78a303a
102
app/acme.hoon
102
app/acme.hoon
@ -278,21 +278,27 @@
|
||||
::
|
||||
++ rs256
|
||||
|_ k=key:rsa
|
||||
++ digest
|
||||
++ emsa :: EMSA-PKCS1-v1_5
|
||||
|= m=@
|
||||
^- @
|
||||
=/ emlen (met 3 n.k)
|
||||
=/ pec=spec:asn1
|
||||
:~ %seq
|
||||
[%seq [%obj sha-256:obj:asn1] [%nul ~] ~]
|
||||
[%oct (shax m)]
|
||||
==
|
||||
(rep 3 ~(ren asn1 pec))
|
||||
=/ t=(list @) ~(ren asn1 pec)
|
||||
=/ tlen (lent t)
|
||||
?: (lth emlen (add 11 tlen))
|
||||
~|(%emsa-too-short !!)
|
||||
=/ ps (reap (sub emlen (add 3 tlen)) 0xff)
|
||||
%+ rep 3
|
||||
(flop (weld [0x0 0x1 ps] [0x0 t]))
|
||||
::
|
||||
++ sign |=(m=@ (de:rsa (digest m) k))
|
||||
++ sign |=(m=@ (de:rsa (emsa m) k))
|
||||
::
|
||||
++ verify
|
||||
|= [s=@ m=@]
|
||||
=((digest m) (en:rsa s k))
|
||||
=((emsa m) (en:rsa s k))
|
||||
--
|
||||
::
|
||||
++ en-json-sort :: print json
|
||||
@ -763,7 +769,91 @@
|
||||
==
|
||||
::
|
||||
++ test-rs256
|
||||
~
|
||||
=/ k1=key:rsa
|
||||
:* 0xf7ef.37e6.7fa6.685a.c178.8b01.cf38.da20.ca4b.de5d.8b01.a71b.d28c.
|
||||
65b4.09c3.6e4d
|
||||
0xc882.5760.3fb8.a5e2.5e9d.db55.3a73.b647.a3ec.a6e9.abc6.c440.dbc7.
|
||||
05f8.2ed4.da6b
|
||||
0xc231.1fc5.fa31.d333.a409.bb4c.e95b.20d2.1cfc.e375.3871.7256.53a2.
|
||||
8425.af6d.e97d.f202.0b23.633f.458d.f12a.6362.7121.bff4.e23c.e578.
|
||||
7e07.7898.0578.61d1.ae60.ac2f
|
||||
0x1.0001
|
||||
0xd91.6719.eb10.3e24.768a.a386.8d2b.6bd0.a26b.dcec.9cc3.f86c.25ad.
|
||||
ce33.dfdc.fb1a.4d50.3e07.3d7f.f5fd.748e.43f8.df02.a60e.d730.5314.
|
||||
3e59.1e70.8df7.2c27.93e2.2b69
|
||||
==
|
||||
=/ inp1 0x302.0101
|
||||
=/ exp1
|
||||
0x575c.8a41.09ed.6ea2.a708.6338.d150.a5bb.8205.142e.7785.47b5.0cc6.0198.
|
||||
6807.0243.bf49.de7c.6039.0160.e392.faca.18f4.a05d.3a7a.88a4.de86.dd99.
|
||||
f030.eb4a.a755.d7ce
|
||||
=/ kpem2=wain
|
||||
:~ '-----BEGIN RSA PRIVATE KEY-----'
|
||||
'MIIEowIBAAKCAQEA2jJp8dgAKy5cSzDE4D+aUbKZsQoMhIWI2IFlE+AO0GCBMig5'
|
||||
'qxx2IIAPVIcSi5fjOLtTHnuIZYw+s06qeb8QIKRvkZaIwnA3Lz5UUrxgh96sezdX'
|
||||
'CCSG7FndIFskcT+zG00JL+fPRdlPjt1Vg2b3kneo5aAKMIPyOTzcY590UTc+luQ3'
|
||||
'HhgSiNF3n5YQh24d3kS2YOUoSXQ13+YRljxNfBgXbV+C7/gO8mFxpkafhmgkIGNe'
|
||||
'WlqT9oAIRa+gOx13uPAg+Jb/8lPV9bGaFqGvxvBMp3xUASlzYHiDntcB5MiOPRW6'
|
||||
'BoIGI5qDFSYRZBky9crE7WAYgqtPtg21zvxwFwIDAQABAoIBAH0q7GGisj4TIziy'
|
||||
'6k1lzwXMuaO4iwO+gokIeU5UessIgTSfpK1G73CnZaPstDPF1r/lncHfxZfTQuij'
|
||||
'WOHsO7kt+x5+R0ebDd0ZGVA45fsrPrCUR2XRZmDRECuOfTJGA13G7F1B0kJUbfIb'
|
||||
'gAGYIK8x236WNyIrntk804SGpTgstCsZ51rK5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ZLMJgdI23FTlPXTEG7PclZSuxBpQpvg3MiVO'
|
||||
'zqVTrhnY+TemcScSx5O6f32aDfOUWWCzmw/gzvJxUYlJqjqd7dlT'
|
||||
'-----END RSA PRIVATE KEY-----'
|
||||
==
|
||||
=/ k2=key:rsa
|
||||
(need (ring:de:pem:rsa kpem2))
|
||||
=/ inp2=cord 'hello\0a'
|
||||
=/ exp2=@ux
|
||||
0x2920.bba3.cb38.bca6.3768.6345.c95e.0717.81bf.6c61.4006.6070.a7b5.e609.
|
||||
f3b4.7f48.878b.d1f8.1882.8852.1db6.b6b5.a5fd.c23b.e764.b910.5a3f.fda9.
|
||||
9d3a.e8bd.060a.ac06.58f1.487a.b50d.dee2.e161.0b74.4d3b.e6e3.7004.c721.
|
||||
4f32.5c95.ce68.a008.b1e9.788b.375f.d389.0fa4.4012.c07a.8319.a183.02d5.
|
||||
e2b8.10df.6ff7.f64a.6b85.3c7d.de80.19cf.ab6d.e588.40cb.0ea4.c436.8d8b.
|
||||
47f7.cce6.b9bf.097d.3275.c128.147a.628d.2b7c.3912.3950.ef68.87b2.180d.
|
||||
ba01.3b05.285d.3dfd.09ee.2f38.3111.9e4c.92c6.bf66.a91b.5762.3cdf.f8b7.
|
||||
8281.81a2.8324.5330.43c1.035a.56c3.71b8.eb85.e660.c3a4.28b4.8af7.c16f.
|
||||
7d7d.87cc.036d.aeb2.c757.30f5.f194.c90d.6bb4.5e5c.f95f.8e28.0fbc.5fb4.
|
||||
b21a.e6fe
|
||||
=/ exp2b64=cord
|
||||
%+ rap 3
|
||||
:~ 'KSC7o8s4vKY3aGNFyV4HF4G/bGFABmBwp7XmCfO0f0iHi9H4GIKIUh22trWl/cI752S5'
|
||||
'EFo//amdOui9BgqsBljxSHq1Dd7i4WELdE075uNwBMchTzJclc5ooAix6XiLN1/TiQ+k'
|
||||
'QBLAeoMZoYMC1eK4EN9v9/ZKa4U8fd6AGc+rbeWIQMsOpMQ2jYtH98zmub8JfTJ1wSgU'
|
||||
'emKNK3w5EjlQ72iHshgNugE7BShdPf0J7i84MRGeTJLGv2apG1diPN/4t4KBgaKDJFMw'
|
||||
'Q8EDWlbDcbjrheZgw6QotIr3wW99fYfMA22ussdXMPXxlMkNa7ReXPlfjigPvF+0shrm'
|
||||
'/g=='
|
||||
==
|
||||
=/ sig=@ux (~(sign rs256 k2) inp2)
|
||||
;: weld
|
||||
%- expect-eq !>
|
||||
[exp1 (~(sign rs256 k1) inp1)]
|
||||
%- expect-eq !>
|
||||
[& (~(verify rs256 k1) exp1 inp1)]
|
||||
%- expect-eq !>
|
||||
[& (~(verify rs256 k2) sig inp2)]
|
||||
%- expect-eq !>
|
||||
[exp2 sig]
|
||||
:: save kpem2 to private.pem
|
||||
:: echo "hello" | openssl dgst -sha256 -sign private.pem | base64
|
||||
%- expect-eq !>
|
||||
[exp2b64 (en:base64 (swp 3 sig))]
|
||||
==
|
||||
::
|
||||
++ testjwkthumbprint
|
||||
=/ n
|
||||
|
Loading…
Reference in New Issue
Block a user