Lines Matching +full:read +full:- +full:to +full:- +full:read
3 \ Permission is hereby granted, free of charge, to any person obtaining
5 \ "Software"), to deal in the Software without restriction, including
6 \ without limitation the rights to use, copy, modify, merge, publish,
7 \ distribute, sublicense, and/or sell copies of the Software, and to
8 \ permit persons to whom the Software is furnished to do so, subject to
15 \ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 #define CTX ((br_skey_decoder_context *)(void *)((unsigned char *)t0ctx - offsetof(br_skey_decode…
35 ctx->cpu.dp = &ctx->dp_stack[0];
36 ctx->cpu.rp = &ctx->rp_stack[0];
37 br_skey_decoder_init_main(&ctx->cpu);
38 br_skey_decoder_run(&ctx->cpu);
46 ctx->hbuf = data;
47 ctx->hlen = len;
48 br_skey_decoder_run(&ctx->cpu);
56 cc: read8-low ( -- x ) {
57 if (CTX->hlen == 0) {
58 T0_PUSHi(-1);
60 CTX->hlen --;
61 T0_PUSH(*CTX->hbuf ++);
65 cc: read-blob-inner ( addr len -- addr len ) {
68 size_t clen = CTX->hlen;
73 memcpy((unsigned char *)CTX + addr, CTX->hbuf, clen);
75 CTX->hbuf += clen;
76 CTX->hlen -= clen;
78 T0_PUSH(len - clen);
82 : len-key_data
86 : addr-len-key_data ( -- addr len )
87 addr-key_data len-key_data ;
90 cc: set-rsa-key ( n_bitlen plen qlen dplen dqlen iqlen -- ) {
99 CTX->key.rsa.n_bitlen = n_bitlen;
100 CTX->key.rsa.p = CTX->key_data;
101 CTX->key.rsa.plen = plen;
103 CTX->key.rsa.q = CTX->key_data + off;
104 CTX->key.rsa.qlen = qlen;
106 CTX->key.rsa.dp = CTX->key_data + off;
107 CTX->key.rsa.dplen = dplen;
109 CTX->key.rsa.dq = CTX->key_data + off;
110 CTX->key.rsa.dqlen = dqlen;
112 CTX->key.rsa.iq = CTX->key_data + off;
113 CTX->key.rsa.iqlen = iqlen;
117 cc: set-ec-key ( curve xlen -- ) {
120 CTX->key.ec.curve = curve;
121 CTX->key.ec.x = CTX->key_data;
122 CTX->key.ec.xlen = xlen;
126 : int-bit-length ( x -- bitlen )
131 \ Read an INTEGER into the key_data buffer, but then ignore it.
132 : read-integer-ignore ( lim -- lim )
133 addr-len-key_data read-integer drop ;
135 \ Read an INTEGER into the key_data buffer, at the provided offset.
137 : read-integer-off ( lim off -- lim dlen )
138 dup addr-len-key_data rot - swap rot + swap read-integer ;
141 : decode-RSA ( lim -- lim )
142 read-sequence-open
145 read-tag 0x02 check-tag-primitive read-small-int-value if
149 \ Read tag for the modulus; should be INTEGER. Then use the
150 \ decode-RSA-next function for the remainder of the key.
151 read-tag 0x02 check-tag-primitive
152 decode-RSA-next
155 close-elt ;
158 \ read.
159 : decode-RSA-next ( lim -- lim )
160 \ Modulus: we read it but we do not keep it; we merely gather
162 addr-len-key_data read-integer-next
164 1- 3 << addr-key_data get8 int-bit-length + { n_bitlen }
166 \ Public exponent: read but skip.
167 read-integer-ignore
169 \ Private exponent: read but skip.
170 read-integer-ignore
173 addr-len-key_data read-integer dup dup { off plen }
176 read-integer-off dup { qlen } off + dup >off
179 read-integer-off dup { dplen } off + dup >off
182 read-integer-off dup { dqlen } off + dup >off
185 read-integer-off { iqlen }
188 n_bitlen plen qlen dplen dqlen iqlen set-rsa-key
195 : decode-EC ( lim curve -- lim )
197 read-sequence-open
200 read-tag 0x02 check-tag-primitive read-small-int-value 1- if
204 \ Read tag for the private key; should be OCTET STRING. Then use the
205 \ decode-EC-next function for the remainder of the key.
206 read-tag 0x04 check-tag-primitive
207 curve decode-EC-next
210 close-elt ;
213 \ already been read. The curve ID is provided (0 if unknown).
214 : decode-EC-next ( lim curve -- lim )
217 \ Read the private key proper.
218 read-length-open-elt
219 dup dup { xlen } len-key_data > if ERR_X509_UNSUPPORTED fail then
220 addr-key_data read-blob
223 read-tag-or-end
227 -1 of drop endof
231 check-constructed read-length-open-elt
232 read-curve-ID
238 close-elt
242 0x21 of check-constructed endof
246 skip-remaining
252 curve xlen set-ec-key
258 \ structure have already been read. This function returns the key type.
259 : decode-PKCS8-next ( lim -- lim keytype )
261 read-length-open-elt
262 read-OID ifnot ERR_X509_UNSUPPORTED fail then
263 { ; is-rsa curve }
267 skip-remaining -1 >is-rsa
269 id-ecPublicKey eqOID uf
272 0 >is-rsa
273 dup if read-curve-ID else 0 then >curve
278 close-elt
281 read-tag 0x04 check-tag-primitive
282 read-length-open-elt
283 is-rsa if
284 decode-RSA
286 curve decode-EC
288 close-elt
291 skip-remaining
294 is-rsa if KEYTYPE_RSA else KEYTYPE_EC then
298 : main ( -- ! )
301 \ version INTEGER, -- 0 or 1
313 \ version 1); thus, we expect the version field to be 0, and
314 \ the 'other' field to be absent.
318 \ version INTEGER, -- always 1
325 \ contents are the unsigned big-endian encoding of the key value,
330 \ version INTEGER, -- 0 or 1
336 \ The 'publicKey' field is an add-on from RFC 5958 and may be
344 read-sequence-open
348 read-tag 0x02 check-tag-primitive read-small-int-value 1 > if
355 read-tag
357 0x02 of check-primitive decode-RSA-next KEYTYPE_RSA endof
358 0x04 of check-primitive 0 decode-EC-next KEYTYPE_EC endof
359 0x10 of check-constructed decode-PKCS8-next endof
362 { key-type }
365 close-elt
368 key-type addr-key_type set8
370 \ Read one byte, then fail: if the read succeeds, then there is
372 read8-nc ERR_X509_EXTRA_ELEMENT fail