2 * RSA implementation for PuTTY.
13 int makekey(const unsigned char *data, int len, struct RSAKey *result,
14 const unsigned char **keystr, int order)
16 const unsigned char *p = data;
24 for (i = 0; i < 4; i++)
25 result->bits = (result->bits << 8) + *p++;
32 * order=0 means exponent then modulus (the keys sent by the
33 * server). order=1 means modulus then exponent (the keys
34 * stored in a keyfile).
38 n = ssh1_read_bignum(p, len, result ? &result->exponent : NULL);
44 n = ssh1_read_bignum(p, len, result ? &result->modulus : NULL);
45 if (n < 0 || (result && bignum_bitcount(result->modulus) == 0)) return -1;
47 result->bytes = n - 2;
54 n = ssh1_read_bignum(p, len, result ? &result->exponent : NULL);
62 int makeprivate(const unsigned char *data, int len, struct RSAKey *result)
64 return ssh1_read_bignum(data, len, &result->private_exponent);
67 int rsaencrypt(unsigned char *data, int length, struct RSAKey *key)
73 if (key->bytes < length + 4)
74 return 0; /* RSA key too short! */
76 memmove(data + key->bytes - length, data, length);
80 for (i = 2; i < key->bytes - length - 1; i++) {
82 data[i] = random_byte();
83 } while (data[i] == 0);
85 data[key->bytes - length - 1] = 0;
87 b1 = bignum_from_bytes(data, key->bytes);
89 b2 = modpow(b1, key->exponent, key->modulus);
92 for (i = key->bytes; i--;) {
93 *p++ = bignum_byte(b2, i);
102 static void sha512_mpint(SHA512_State * s, Bignum b)
104 unsigned char lenbuf[4];
106 len = (bignum_bitcount(b) + 8) / 8;
107 PUT_32BIT(lenbuf, len);
108 SHA512_Bytes(s, lenbuf, 4);
110 lenbuf[0] = bignum_byte(b, len);
111 SHA512_Bytes(s, lenbuf, 1);
113 smemclr(lenbuf, sizeof(lenbuf));
117 * Compute (base ^ exp) % mod, provided mod == p * q, with p,q
118 * distinct primes, and iqmp is the multiplicative inverse of q mod p.
119 * Uses Chinese Remainder Theorem to speed computation up over the
120 * obvious implementation of a single big modpow.
122 Bignum crt_modpow(Bignum base, Bignum exp, Bignum mod,
123 Bignum p, Bignum q, Bignum iqmp)
125 Bignum pm1, qm1, pexp, qexp, presult, qresult, diff, multiplier, ret0, ret;
128 * Reduce the exponent mod phi(p) and phi(q), to save time when
129 * exponentiating mod p and mod q respectively. Of course, since p
130 * and q are prime, phi(p) == p-1 and similarly for q.
136 pexp = bigmod(exp, pm1);
137 qexp = bigmod(exp, qm1);
140 * Do the two modpows.
142 presult = modpow(base, pexp, p);
143 qresult = modpow(base, qexp, q);
146 * Recombine the results. We want a value which is congruent to
147 * qresult mod q, and to presult mod p.
149 * We know that iqmp * q is congruent to 1 * mod p (by definition
150 * of iqmp) and to 0 mod q (obviously). So we start with qresult
151 * (which is congruent to qresult mod both primes), and add on
152 * (presult-qresult) * (iqmp * q) which adjusts it to be congruent
153 * to presult mod p without affecting its value mod q.
155 if (bignum_cmp(presult, qresult) < 0) {
157 * Can't subtract presult from qresult without first adding on
160 Bignum tmp = presult;
161 presult = bigadd(presult, p);
164 diff = bigsub(presult, qresult);
165 multiplier = bigmul(iqmp, q);
166 ret0 = bigmuladd(multiplier, diff, qresult);
169 * Finally, reduce the result mod n.
171 ret = bigmod(ret0, mod);
174 * Free all the intermediate results before returning.
190 * This function is a wrapper on modpow(). It has the same effect as
191 * modpow(), but employs RSA blinding to protect against timing
192 * attacks and also uses the Chinese Remainder Theorem (implemented
193 * above, in crt_modpow()) to speed up the main operation.
195 static Bignum rsa_privkey_op(Bignum input, struct RSAKey *key)
197 Bignum random, random_encrypted, random_inverse;
198 Bignum input_blinded, ret_blinded;
202 unsigned char digest512[64];
203 int digestused = lenof(digest512);
207 * Start by inventing a random number chosen uniformly from the
208 * range 2..modulus-1. (We do this by preparing a random number
209 * of the right length and retrying if it's greater than the
210 * modulus, to prevent any potential Bleichenbacher-like
211 * attacks making use of the uneven distribution within the
212 * range that would arise from just reducing our number mod n.
213 * There are timing implications to the potential retries, of
214 * course, but all they tell you is the modulus, which you
217 * To preserve determinism and avoid Pageant needing to share
218 * the random number pool, we actually generate this `random'
219 * number by hashing stuff with the private key.
222 int bits, byte, bitsleft, v;
223 random = copybn(key->modulus);
225 * Find the topmost set bit. (This function will return its
226 * index plus one.) Then we'll set all bits from that one
227 * downwards randomly.
229 bits = bignum_bitcount(random);
236 * Conceptually the following few lines are equivalent to
237 * byte = random_byte();
239 if (digestused >= lenof(digest512)) {
240 unsigned char seqbuf[4];
241 PUT_32BIT(seqbuf, hashseq);
243 SHA512_Bytes(&ss, "RSA deterministic blinding", 26);
244 SHA512_Bytes(&ss, seqbuf, sizeof(seqbuf));
245 sha512_mpint(&ss, key->private_exponent);
246 SHA512_Final(&ss, digest512);
250 * Now hash that digest plus the signature
254 SHA512_Bytes(&ss, digest512, sizeof(digest512));
255 sha512_mpint(&ss, input);
256 SHA512_Final(&ss, digest512);
260 byte = digest512[digestused++];
265 bignum_set_bit(random, bits, v);
267 bn_restore_invariant(random);
270 * Now check that this number is strictly greater than
271 * zero, and strictly less than modulus.
273 if (bignum_cmp(random, Zero) <= 0 ||
274 bignum_cmp(random, key->modulus) >= 0) {
280 * Also, make sure it has an inverse mod modulus.
282 random_inverse = modinv(random, key->modulus);
283 if (!random_inverse) {
292 * RSA blinding relies on the fact that (xy)^d mod n is equal
293 * to (x^d mod n) * (y^d mod n) mod n. We invent a random pair
294 * y and y^d; then we multiply x by y, raise to the power d mod
295 * n as usual, and divide by y^d to recover x^d. Thus an
296 * attacker can't correlate the timing of the modpow with the
297 * input, because they don't know anything about the number
298 * that was input to the actual modpow.
300 * The clever bit is that we don't have to do a huge modpow to
301 * get y and y^d; we will use the number we just invented as
302 * _y^d_, and use the _public_ exponent to compute (y^d)^e = y
303 * from it, which is much faster to do.
305 random_encrypted = crt_modpow(random, key->exponent,
306 key->modulus, key->p, key->q, key->iqmp);
307 input_blinded = modmul(input, random_encrypted, key->modulus);
308 ret_blinded = crt_modpow(input_blinded, key->private_exponent,
309 key->modulus, key->p, key->q, key->iqmp);
310 ret = modmul(ret_blinded, random_inverse, key->modulus);
313 freebn(input_blinded);
314 freebn(random_inverse);
315 freebn(random_encrypted);
321 Bignum rsadecrypt(Bignum input, struct RSAKey *key)
323 return rsa_privkey_op(input, key);
326 int rsastr_len(struct RSAKey *key)
333 mdlen = (bignum_bitcount(md) + 15) / 16;
334 exlen = (bignum_bitcount(ex) + 15) / 16;
335 return 4 * (mdlen + exlen) + 20;
338 void rsastr_fmt(char *str, struct RSAKey *key)
341 int len = 0, i, nibbles;
342 static const char hex[] = "0123456789abcdef";
347 len += sprintf(str + len, "0x");
349 nibbles = (3 + bignum_bitcount(ex)) / 4;
352 for (i = nibbles; i--;)
353 str[len++] = hex[(bignum_byte(ex, i / 2) >> (4 * (i % 2))) & 0xF];
355 len += sprintf(str + len, ",0x");
357 nibbles = (3 + bignum_bitcount(md)) / 4;
360 for (i = nibbles; i--;)
361 str[len++] = hex[(bignum_byte(md, i / 2) >> (4 * (i % 2))) & 0xF];
367 * Generate a fingerprint string for the key. Compatible with the
368 * OpenSSH fingerprint code.
370 void rsa_fingerprint(char *str, int len, struct RSAKey *key)
372 struct MD5Context md5c;
373 unsigned char digest[16];
374 char buffer[16 * 3 + 40];
378 numlen = ssh1_bignum_length(key->modulus) - 2;
379 for (i = numlen; i--;) {
380 unsigned char c = bignum_byte(key->modulus, i);
381 MD5Update(&md5c, &c, 1);
383 numlen = ssh1_bignum_length(key->exponent) - 2;
384 for (i = numlen; i--;) {
385 unsigned char c = bignum_byte(key->exponent, i);
386 MD5Update(&md5c, &c, 1);
388 MD5Final(digest, &md5c);
390 sprintf(buffer, "%d ", bignum_bitcount(key->modulus));
391 for (i = 0; i < 16; i++)
392 sprintf(buffer + strlen(buffer), "%s%02x", i ? ":" : "",
394 strncpy(str, buffer, len);
397 if (key->comment && slen < len - 1) {
399 strncpy(str + slen + 1, key->comment, len - slen - 1);
405 * Verify that the public data in an RSA key matches the private
406 * data. We also check the private data itself: we ensure that p >
407 * q and that iqmp really is the inverse of q mod p.
409 int rsa_verify(struct RSAKey *key)
411 Bignum n, ed, pm1, qm1;
414 /* n must equal pq. */
415 n = bigmul(key->p, key->q);
416 cmp = bignum_cmp(n, key->modulus);
421 /* e * d must be congruent to 1, modulo (p-1) and modulo (q-1). */
422 pm1 = copybn(key->p);
424 ed = modmul(key->exponent, key->private_exponent, pm1);
426 cmp = bignum_cmp(ed, One);
431 qm1 = copybn(key->q);
433 ed = modmul(key->exponent, key->private_exponent, qm1);
435 cmp = bignum_cmp(ed, One);
443 * I have seen key blobs in the wild which were generated with
444 * p < q, so instead of rejecting the key in this case we
445 * should instead flip them round into the canonical order of
446 * p > q. This also involves regenerating iqmp.
448 if (bignum_cmp(key->p, key->q) <= 0) {
454 key->iqmp = modinv(key->q, key->p);
460 * Ensure iqmp * q is congruent to 1, modulo p.
462 n = modmul(key->iqmp, key->q, key->p);
463 cmp = bignum_cmp(n, One);
471 /* Public key blob as used by Pageant: exponent before modulus. */
472 unsigned char *rsa_public_blob(struct RSAKey *key, int *len)
477 length = (ssh1_bignum_length(key->modulus) +
478 ssh1_bignum_length(key->exponent) + 4);
479 ret = snewn(length, unsigned char);
481 PUT_32BIT(ret, bignum_bitcount(key->modulus));
483 pos += ssh1_write_bignum(ret + pos, key->exponent);
484 pos += ssh1_write_bignum(ret + pos, key->modulus);
490 /* Given a public blob, determine its length. */
491 int rsa_public_blob_len(void *data, int maxlen)
493 unsigned char *p = (unsigned char *)data;
498 p += 4; /* length word */
501 n = ssh1_read_bignum(p, maxlen, NULL); /* exponent */
506 n = ssh1_read_bignum(p, maxlen, NULL); /* modulus */
511 return p - (unsigned char *)data;
514 void freersakey(struct RSAKey *key)
517 freebn(key->modulus);
519 freebn(key->exponent);
520 if (key->private_exponent)
521 freebn(key->private_exponent);
532 /* ----------------------------------------------------------------------
533 * Implementation of the ssh-rsa signing key type.
536 static void getstring(const char **data, int *datalen,
537 const char **p, int *length)
542 *length = toint(GET_32BIT(*data));
547 if (*datalen < *length)
553 static Bignum getmp(const char **data, int *datalen)
559 getstring(data, datalen, &p, &length);
562 b = bignum_from_bytes((unsigned char *)p, length);
566 static void rsa2_freekey(void *key); /* forward reference */
568 static void *rsa2_newkey(const struct ssh_signkey *self,
569 const char *data, int len)
575 rsa = snew(struct RSAKey);
576 getstring(&data, &len, &p, &slen);
578 if (!p || slen != 7 || memcmp(p, "ssh-rsa", 7)) {
582 rsa->exponent = getmp(&data, &len);
583 rsa->modulus = getmp(&data, &len);
584 rsa->private_exponent = NULL;
585 rsa->p = rsa->q = rsa->iqmp = NULL;
588 if (!rsa->exponent || !rsa->modulus) {
596 static void rsa2_freekey(void *key)
598 struct RSAKey *rsa = (struct RSAKey *) key;
603 static char *rsa2_fmtkey(void *key)
605 struct RSAKey *rsa = (struct RSAKey *) key;
609 len = rsastr_len(rsa);
610 p = snewn(len, char);
615 static unsigned char *rsa2_public_blob(void *key, int *len)
617 struct RSAKey *rsa = (struct RSAKey *) key;
618 int elen, mlen, bloblen;
620 unsigned char *blob, *p;
622 elen = (bignum_bitcount(rsa->exponent) + 8) / 8;
623 mlen = (bignum_bitcount(rsa->modulus) + 8) / 8;
626 * string "ssh-rsa", mpint exp, mpint mod. Total 19+elen+mlen.
627 * (three length fields, 12+7=19).
629 bloblen = 19 + elen + mlen;
630 blob = snewn(bloblen, unsigned char);
634 memcpy(p, "ssh-rsa", 7);
639 *p++ = bignum_byte(rsa->exponent, i);
643 *p++ = bignum_byte(rsa->modulus, i);
644 assert(p == blob + bloblen);
649 static unsigned char *rsa2_private_blob(void *key, int *len)
651 struct RSAKey *rsa = (struct RSAKey *) key;
652 int dlen, plen, qlen, ulen, bloblen;
654 unsigned char *blob, *p;
656 dlen = (bignum_bitcount(rsa->private_exponent) + 8) / 8;
657 plen = (bignum_bitcount(rsa->p) + 8) / 8;
658 qlen = (bignum_bitcount(rsa->q) + 8) / 8;
659 ulen = (bignum_bitcount(rsa->iqmp) + 8) / 8;
662 * mpint private_exp, mpint p, mpint q, mpint iqmp. Total 16 +
665 bloblen = 16 + dlen + plen + qlen + ulen;
666 blob = snewn(bloblen, unsigned char);
671 *p++ = bignum_byte(rsa->private_exponent, i);
675 *p++ = bignum_byte(rsa->p, i);
679 *p++ = bignum_byte(rsa->q, i);
683 *p++ = bignum_byte(rsa->iqmp, i);
684 assert(p == blob + bloblen);
689 static void *rsa2_createkey(const struct ssh_signkey *self,
690 const unsigned char *pub_blob, int pub_len,
691 const unsigned char *priv_blob, int priv_len)
694 const char *pb = (const char *) priv_blob;
696 rsa = rsa2_newkey(self, (char *) pub_blob, pub_len);
697 rsa->private_exponent = getmp(&pb, &priv_len);
698 rsa->p = getmp(&pb, &priv_len);
699 rsa->q = getmp(&pb, &priv_len);
700 rsa->iqmp = getmp(&pb, &priv_len);
702 if (!rsa_verify(rsa)) {
710 static void *rsa2_openssh_createkey(const struct ssh_signkey *self,
711 const unsigned char **blob, int *len)
713 const char **b = (const char **) blob;
716 rsa = snew(struct RSAKey);
719 rsa->modulus = getmp(b, len);
720 rsa->exponent = getmp(b, len);
721 rsa->private_exponent = getmp(b, len);
722 rsa->iqmp = getmp(b, len);
723 rsa->p = getmp(b, len);
724 rsa->q = getmp(b, len);
726 if (!rsa->modulus || !rsa->exponent || !rsa->private_exponent ||
727 !rsa->iqmp || !rsa->p || !rsa->q) {
732 if (!rsa_verify(rsa)) {
740 static int rsa2_openssh_fmtkey(void *key, unsigned char *blob, int len)
742 struct RSAKey *rsa = (struct RSAKey *) key;
746 ssh2_bignum_length(rsa->modulus) +
747 ssh2_bignum_length(rsa->exponent) +
748 ssh2_bignum_length(rsa->private_exponent) +
749 ssh2_bignum_length(rsa->iqmp) +
750 ssh2_bignum_length(rsa->p) + ssh2_bignum_length(rsa->q);
757 PUT_32BIT(blob+bloblen, ssh2_bignum_length((x))-4); bloblen += 4; \
758 for (i = ssh2_bignum_length((x))-4; i-- ;) blob[bloblen++]=bignum_byte((x),i);
761 ENC(rsa->private_exponent);
769 static int rsa2_pubkey_bits(const struct ssh_signkey *self,
770 const void *blob, int len)
775 rsa = rsa2_newkey(self, (const char *) blob, len);
776 ret = bignum_bitcount(rsa->modulus);
783 * This is the magic ASN.1/DER prefix that goes in the decoded
784 * signature, between the string of FFs and the actual SHA hash
785 * value. The meaning of it is:
787 * 00 -- this marks the end of the FFs; not part of the ASN.1 bit itself
789 * 30 21 -- a constructed SEQUENCE of length 0x21
790 * 30 09 -- a constructed sub-SEQUENCE of length 9
791 * 06 05 -- an object identifier, length 5
792 * 2B 0E 03 02 1A -- object id { 1 3 14 3 2 26 }
793 * (the 1,3 comes from 0x2B = 43 = 40*1+3)
795 * 04 14 -- a primitive OCTET STRING of length 0x14
796 * [0x14 bytes of hash data follows]
798 * The object id in the middle there is listed as `id-sha1' in
799 * ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1d2.asn (the
800 * ASN module for PKCS #1) and its expanded form is as follows:
802 * id-sha1 OBJECT IDENTIFIER ::= {
803 * iso(1) identified-organization(3) oiw(14) secsig(3)
806 static const unsigned char asn1_weird_stuff[] = {
807 0x00, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B,
808 0x0E, 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14,
811 #define ASN1_LEN ( (int) sizeof(asn1_weird_stuff) )
813 static int rsa2_verifysig(void *key, const char *sig, int siglen,
814 const char *data, int datalen)
816 struct RSAKey *rsa = (struct RSAKey *) key;
820 int bytes, i, j, ret;
821 unsigned char hash[20];
823 getstring(&sig, &siglen, &p, &slen);
824 if (!p || slen != 7 || memcmp(p, "ssh-rsa", 7)) {
827 in = getmp(&sig, &siglen);
830 out = modpow(in, rsa->exponent, rsa->modulus);
835 bytes = (bignum_bitcount(rsa->modulus)+7) / 8;
836 /* Top (partial) byte should be zero. */
837 if (bignum_byte(out, bytes - 1) != 0)
839 /* First whole byte should be 1. */
840 if (bignum_byte(out, bytes - 2) != 1)
842 /* Most of the rest should be FF. */
843 for (i = bytes - 3; i >= 20 + ASN1_LEN; i--) {
844 if (bignum_byte(out, i) != 0xFF)
847 /* Then we expect to see the asn1_weird_stuff. */
848 for (i = 20 + ASN1_LEN - 1, j = 0; i >= 20; i--, j++) {
849 if (bignum_byte(out, i) != asn1_weird_stuff[j])
852 /* Finally, we expect to see the SHA-1 hash of the signed data. */
853 SHA_Simple(data, datalen, hash);
854 for (i = 19, j = 0; i >= 0; i--, j++) {
855 if (bignum_byte(out, i) != hash[j])
863 static unsigned char *rsa2_sign(void *key, const char *data, int datalen,
866 struct RSAKey *rsa = (struct RSAKey *) key;
867 unsigned char *bytes;
869 unsigned char hash[20];
873 SHA_Simple(data, datalen, hash);
875 nbytes = (bignum_bitcount(rsa->modulus) - 1) / 8;
876 assert(1 <= nbytes - 20 - ASN1_LEN);
877 bytes = snewn(nbytes, unsigned char);
880 for (i = 1; i < nbytes - 20 - ASN1_LEN; i++)
882 for (i = nbytes - 20 - ASN1_LEN, j = 0; i < nbytes - 20; i++, j++)
883 bytes[i] = asn1_weird_stuff[j];
884 for (i = nbytes - 20, j = 0; i < nbytes; i++, j++)
887 in = bignum_from_bytes(bytes, nbytes);
890 out = rsa_privkey_op(in, rsa);
893 nbytes = (bignum_bitcount(out) + 7) / 8;
894 bytes = snewn(4 + 7 + 4 + nbytes, unsigned char);
896 memcpy(bytes + 4, "ssh-rsa", 7);
897 PUT_32BIT(bytes + 4 + 7, nbytes);
898 for (i = 0; i < nbytes; i++)
899 bytes[4 + 7 + 4 + i] = bignum_byte(out, nbytes - 1 - i);
902 *siglen = 4 + 7 + 4 + nbytes;
906 const struct ssh_signkey ssh_rsa = {
913 rsa2_openssh_createkey,
915 6 /* n,e,d,iqmp,q,p */,
924 void *ssh_rsakex_newkey(char *data, int len)
926 return rsa2_newkey(&ssh_rsa, data, len);
929 void ssh_rsakex_freekey(void *key)
934 int ssh_rsakex_klen(void *key)
936 struct RSAKey *rsa = (struct RSAKey *) key;
938 return bignum_bitcount(rsa->modulus);
941 static void oaep_mask(const struct ssh_hash *h, void *seed, int seedlen,
942 void *vdata, int datalen)
944 unsigned char *data = (unsigned char *)vdata;
947 while (datalen > 0) {
948 int i, max = (datalen > h->hlen ? h->hlen : datalen);
950 unsigned char counter[4], hash[SSH2_KEX_MAX_HASH_LEN];
952 assert(h->hlen <= SSH2_KEX_MAX_HASH_LEN);
953 PUT_32BIT(counter, count);
955 h->bytes(s, seed, seedlen);
956 h->bytes(s, counter, 4);
960 for (i = 0; i < max; i++)
968 void ssh_rsakex_encrypt(const struct ssh_hash *h, unsigned char *in, int inlen,
969 unsigned char *out, int outlen,
973 struct RSAKey *rsa = (struct RSAKey *) key;
976 const int HLEN = h->hlen;
979 * Here we encrypt using RSAES-OAEP. Essentially this means:
981 * - we have a SHA-based `mask generation function' which
982 * creates a pseudo-random stream of mask data
983 * deterministically from an input chunk of data.
985 * - we have a random chunk of data called a seed.
987 * - we use the seed to generate a mask which we XOR with our
990 * - then we use _the masked plaintext_ to generate a mask
991 * which we XOR with the seed.
993 * - then we concatenate the masked seed and the masked
994 * plaintext, and RSA-encrypt that lot.
996 * The result is that the data input to the encryption function
997 * is random-looking and (hopefully) contains no exploitable
998 * structure such as PKCS1-v1_5 does.
1000 * For a precise specification, see RFC 3447, section 7.1.1.
1001 * Some of the variable names below are derived from that, so
1002 * it'd probably help to read it anyway.
1005 /* k denotes the length in octets of the RSA modulus. */
1006 k = (7 + bignum_bitcount(rsa->modulus)) / 8;
1008 /* The length of the input data must be at most k - 2hLen - 2. */
1009 assert(inlen > 0 && inlen <= k - 2*HLEN - 2);
1011 /* The length of the output data wants to be precisely k. */
1012 assert(outlen == k);
1015 * Now perform EME-OAEP encoding. First set up all the unmasked
1018 /* Leading byte zero. */
1020 /* At position 1, the seed: HLEN bytes of random data. */
1021 for (i = 0; i < HLEN; i++)
1022 out[i + 1] = random_byte();
1023 /* At position 1+HLEN, the data block DB, consisting of: */
1024 /* The hash of the label (we only support an empty label here) */
1025 h->final(h->init(), out + HLEN + 1);
1026 /* A bunch of zero octets */
1027 memset(out + 2*HLEN + 1, 0, outlen - (2*HLEN + 1));
1028 /* A single 1 octet, followed by the input message data. */
1029 out[outlen - inlen - 1] = 1;
1030 memcpy(out + outlen - inlen, in, inlen);
1033 * Now use the seed data to mask the block DB.
1035 oaep_mask(h, out+1, HLEN, out+HLEN+1, outlen-HLEN-1);
1038 * And now use the masked DB to mask the seed itself.
1040 oaep_mask(h, out+HLEN+1, outlen-HLEN-1, out+1, HLEN);
1043 * Now `out' contains precisely the data we want to
1046 b1 = bignum_from_bytes(out, outlen);
1047 b2 = modpow(b1, rsa->exponent, rsa->modulus);
1049 for (i = outlen; i--;) {
1050 *p++ = bignum_byte(b2, i);
1060 static const struct ssh_kex ssh_rsa_kex_sha1 = {
1061 "rsa1024-sha1", NULL, KEXTYPE_RSA, &ssh_sha1, NULL,
1064 static const struct ssh_kex ssh_rsa_kex_sha256 = {
1065 "rsa2048-sha256", NULL, KEXTYPE_RSA, &ssh_sha256, NULL,
1068 static const struct ssh_kex *const rsa_kex_list[] = {
1069 &ssh_rsa_kex_sha256,
1073 const struct ssh_kexes ssh_rsa_kex = {
1074 sizeof(rsa_kex_list) / sizeof(*rsa_kex_list),