test RSA_generate_key_ex
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19698 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -65,7 +65,7 @@ check_rsa(const unsigned char *in, size_t len, RSA *rsa, int padding)
|
||||
|
||||
keylen = RSA_private_encrypt(len, in, res, rsa, padding);
|
||||
if (keylen <= 0)
|
||||
errx(1, "failed to private encrypt: %d", (int)len, (int)keylen);
|
||||
errx(1, "failed to private encrypt: %d %d", (int)len, (int)keylen);
|
||||
|
||||
if (keylen > RSA_size(rsa))
|
||||
errx(1, "keylen > RSA_size(rsa)");
|
||||
@@ -103,6 +103,12 @@ check_rsa(const unsigned char *in, size_t len, RSA *rsa, int padding)
|
||||
free(res2);
|
||||
}
|
||||
|
||||
static int
|
||||
cb_func(int a, int b, BN_GENCB *c)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
@@ -173,10 +179,7 @@ main(int argc, char **argv)
|
||||
|
||||
printf("rsa %s\n", ENGINE_get_RSA(engine)->name);
|
||||
|
||||
if (rsa_key == NULL)
|
||||
errx(1, "missing rsa key flag!");
|
||||
|
||||
{
|
||||
if (rsa_key) {
|
||||
unsigned char buf[1024 * 4];
|
||||
const unsigned char *p;
|
||||
size_t size;
|
||||
@@ -199,7 +202,6 @@ main(int argc, char **argv)
|
||||
err(1, "failed to parse key in file %s", rsa_key);
|
||||
|
||||
RSA_set_method(rsa, ENGINE_get_RSA(engine));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@@ -237,6 +239,32 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
RSA_free(rsa);
|
||||
}
|
||||
|
||||
{
|
||||
BN_GENCB cb;
|
||||
BIGNUM *e;
|
||||
|
||||
rsa = RSA_new_method(engine);
|
||||
|
||||
e = BN_new();
|
||||
BN_set_word(e, 0x10001);
|
||||
|
||||
BN_GENCB_set(&cb, cb_func, NULL);
|
||||
|
||||
if (RSA_generate_key_ex(rsa, 1024, e, &cb) != 1)
|
||||
errx(1, "RSA_generate_key_ex");
|
||||
|
||||
BN_free(e);
|
||||
|
||||
{
|
||||
unsigned char sha1[20];
|
||||
RAND_bytes(sha1, sizeof(sha1));
|
||||
check_rsa(sha1, sizeof(sha1), rsa, RSA_PKCS1_PADDING);
|
||||
}
|
||||
|
||||
RSA_free(rsa);
|
||||
}
|
||||
|
||||
ENGINE_finish(engine);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user