-void freersakey(struct RSAKey *key) {
- if (key->modulus) freebn(key->modulus);
- if (key->exponent) freebn(key->exponent);
- if (key->private_exponent) freebn(key->private_exponent);
- if (key->comment) sfree(key->comment);
+/* Public key blob as used by Pageant: exponent before modulus. */
+unsigned char *rsa_public_blob(struct RSAKey *key, int *len)
+{
+ int length, pos;
+ unsigned char *ret;
+
+ length = (ssh1_bignum_length(key->modulus) +
+ ssh1_bignum_length(key->exponent) + 4);
+ ret = smalloc(length);
+
+ PUT_32BIT(ret, bignum_bitcount(key->modulus));
+ pos = 4;
+ pos += ssh1_write_bignum(ret + pos, key->exponent);
+ pos += ssh1_write_bignum(ret + pos, key->modulus);
+
+ *len = length;
+ return ret;
+}
+
+/* Given a public blob, determine its length. */
+int rsa_public_blob_len(void *data)
+{
+ unsigned char *p = (unsigned char *)data;
+
+ p += 4; /* length word */
+ p += ssh1_read_bignum(p, NULL); /* exponent */
+ p += ssh1_read_bignum(p, NULL); /* modulus */
+
+ return p - (unsigned char *)data;
+}
+
+void freersakey(struct RSAKey *key)
+{
+ if (key->modulus)
+ freebn(key->modulus);
+ if (key->exponent)
+ freebn(key->exponent);
+ if (key->private_exponent)
+ freebn(key->private_exponent);
+ if (key->comment)
+ sfree(key->comment);