-#ifdef TESTMODE
-
-#ifndef NODDY
-#define p1 10007
-#define p2 10069
-#define p3 10177
-#else
-#define p1 3
-#define p2 7
-#define p3 13
-#endif
-
-unsigned short P1[2] = { 1, p1 };
-unsigned short P2[2] = { 1, p2 };
-unsigned short P3[2] = { 1, p3 };
-unsigned short bigmod[5] = { 4, 0, 0, 0, 32768U };
-unsigned short mod[5] = { 4, 0, 0, 0, 0 };
-unsigned short a[5] = { 4, 0, 0, 0, 0 };
-unsigned short b[5] = { 4, 0, 0, 0, 0 };
-unsigned short c[5] = { 4, 0, 0, 0, 0 };
-unsigned short One[2] = { 1, 1 };
-unsigned short Two[2] = { 1, 2 };
-
-int main(void) {
- modmult(P1, P2, bigmod, a); debug(a);
- modmult(a, P3, bigmod, mod); debug(mod);
-
- sub(P1, One, a); debug(a);
- sub(P2, One, b); debug(b);
- modmult(a, b, bigmod, c); debug(c);
- sub(P3, One, a); debug(a);
- modmult(a, c, bigmod, b); debug(b);
-
- modpow(Two, b, mod, a); debug(a);
-
- return 0;
+unsigned char *rsa2_sign(void *key, char *data, int datalen, int *siglen) {
+ struct RSAKey *rsa = (struct RSAKey *)key;
+ unsigned char *bytes;
+ int nbytes;
+ unsigned char hash[20];
+ Bignum in, out;
+ int i, j;
+
+ SHA_Simple(data, datalen, hash);
+
+ nbytes = (ssh1_bignum_bitcount(rsa->modulus)-1) / 8;
+ bytes = smalloc(nbytes);
+
+ bytes[0] = 1;
+ for (i = 1; i < nbytes-20-ASN1_LEN; i++)
+ bytes[i] = 0xFF;
+ for (i = nbytes-20-ASN1_LEN, j=0; i < nbytes-20; i++,j++)
+ bytes[i] = asn1_weird_stuff[j];
+ for (i = nbytes-20, j=0; i < nbytes; i++,j++)
+ bytes[i] = hash[j];
+
+ in = bignum_from_bytes(bytes, nbytes);
+ sfree(bytes);
+
+ out = modpow(in, rsa->private_exponent, rsa->modulus);
+ freebn(in);
+
+ nbytes = (ssh1_bignum_bitcount(out)+7)/8;
+ bytes = smalloc(4+7+4+nbytes);
+ PUT_32BIT(bytes, 7);
+ memcpy(bytes+4, "ssh-rsa", 7);
+ PUT_32BIT(bytes+4+7, nbytes);
+ for (i = 0; i < nbytes; i++)
+ bytes[4+7+4+i] = bignum_byte(out, nbytes-1-i);
+ freebn(out);
+
+ *siglen = 4+7+4+nbytes;
+ return bytes;