Expose key generation functions in testcrypt.

They're not much use for 'real' key generation, since like all the
other randomness-using testcrypt functions, they need you to have
explicitly queued up some random data. But for generating keys for
test purposes, they have the great virtue that they deliver the key in
the internal format, where we can generate all the various public and
private blobs from it as well as the on-disk formats.

A minor change to one of the keygen functions itself: rsa_generate now
fills in the 'bits' and 'bytes' fields of the returned RSAKey, without
which it didn't actually work to try to generate a public blob from
it. (We'd never noticed before, because no previous client of
rsa_generate even tried that.)
This commit is contained in:
Simon Tatham 2020-01-09 07:21:30 +00:00
Родитель 13e988b6ee
Коммит 8a87f4509c
4 изменённых файлов: 66 добавлений и 7 удалений

15
Recipe
Просмотреть файл

@ -322,6 +322,9 @@ W_BE_NOSSH = be_nos_s winser nocproxy
U_BE_ALL = be_all_s uxser cproxy
U_BE_NOSSH = be_nos_s uxser nocproxy
# Auxiliary crypto modules used by key generators.
KEYGEN = sshrsag sshdssg sshecdsag
# ------------------------------------------------------------
# Definitions of actual programs. The program name, followed by a
# colon, followed by a list of objects. Also in the list may be the
@ -343,11 +346,11 @@ pageant : [G] winpgnt pageant sshrsa sshpubk sshdes ARITH sshmd5 version
+ sshauxcrypt sshhmac wincapi winnps winnpc winhsock errsock winnet
+ winhandl callback be_misc winselgui winhandl LIBS
puttygen : [G] winpgen sshrsag sshdssg sshprime sshdes ARITH sshmd5 version
puttygen : [G] winpgen KEYGEN sshprime sshdes ARITH sshmd5 version
+ sshrand winnoise sshsha winstore MISC winctrls sshrsa sshdss winmisc
+ sshpubk sshaes sshsh256 sshsh512 IMPORT winutils puttygen.res
+ tree234 notiming winhelp winnojmp CONF LIBS wintime sshecc sshprng
+ sshecdsag sshauxcrypt sshhmac winsecur winmiscs
+ sshauxcrypt sshhmac winsecur winmiscs
pterm : [X] GTKTERM uxmisc misc ldisc settings uxpty uxsel BE_NONE uxstore
+ uxsignal CHARSET cmdline uxpterm version time xpmpterm xpmptcfg
@ -362,10 +365,10 @@ puttytel : [X] GTKTERM uxmisc misc ldisc settings uxsel U_BE_NOSSH
plink : [U] uxplink uxcons NONSSH UXSSH U_BE_ALL logging UXMISC uxsignal
+ ux_x11 noterm uxnogtk sessprep cmdline
PUTTYGEN_UNIX = sshrsag sshdssg sshprime sshdes ARITH sshmd5 version sshprng
PUTTYGEN_UNIX = KEYGEN sshprime sshdes ARITH sshmd5 version sshprng
+ sshrand uxnoise sshsha MISC sshrsa sshdss uxcons uxstore uxmisc
+ sshpubk sshaes sshsh256 sshsh512 IMPORT puttygen.res time tree234
+ uxgen notiming CONF sshecc sshecdsag uxnogtk sshauxcrypt sshhmac
+ uxgen notiming CONF sshecc uxnogtk sshauxcrypt sshhmac
+ uxpoll uxutils
puttygen : [U] cmdgen PUTTYGEN_UNIX
cgtest : [UT] cgtest PUTTYGEN_UNIX
@ -390,9 +393,9 @@ osxlaunch : [UT] osxlaunch
fuzzterm : [UT] UXTERM CHARSET MISC version uxmisc uxucs fuzzterm time settings
+ uxstore be_none uxnogtk memory
testcrypt : [UT] testcrypt SSHCRYPTO sshprng sshprime marshal utils
+ memory tree234 uxutils
+ memory tree234 uxutils KEYGEN
testcrypt : [C] testcrypt SSHCRYPTO sshprng sshprime marshal utils
+ memory tree234 winmiscs
+ memory tree234 winmiscs KEYGEN
testsc : [UT] testsc SSHCRYPTO marshal utils memory tree234 wildcard
+ sshmac uxutils
testzlib : [UT] testzlib sshzlib utils marshal memory

Просмотреть файл

@ -124,5 +124,8 @@ int rsa_generate(RSAKey *key, int bits, progfn_t pfn,
key->q = q;
key->iqmp = iqmp;
key->bits = mp_get_nbits(modulus);
key->bytes = (key->bits + 7) / 8;
return 1;
}

Просмотреть файл

@ -920,6 +920,50 @@ mp_int *primegen_wrapper(
}
#define primegen primegen_wrapper
RSAKey *rsa1_generate(int bits)
{
RSAKey *rsakey = snew(RSAKey);
rsa_generate(rsakey, bits, no_progress, NULL);
rsakey->comment = NULL;
return rsakey;
}
ssh_key *rsa_generate_wrapper(int bits)
{
return &rsa1_generate(bits)->sshk;
}
#define rsa_generate rsa_generate_wrapper
ssh_key *dsa_generate_wrapper(int bits)
{
struct dss_key *dsskey = snew(struct dss_key);
dsa_generate(dsskey, bits, no_progress, NULL);
return &dsskey->sshk;
}
#define dsa_generate dsa_generate_wrapper
ssh_key *ecdsa_generate_wrapper(int bits)
{
struct ecdsa_key *ek = snew(struct ecdsa_key);
if (!ecdsa_generate(ek, bits, no_progress, NULL)) {
sfree(ek);
return NULL;
}
return &ek->sshk;
}
#define ecdsa_generate ecdsa_generate_wrapper
ssh_key *eddsa_generate_wrapper(int bits)
{
struct eddsa_key *ek = snew(struct eddsa_key);
if (!eddsa_generate(ek, bits, no_progress, NULL)) {
sfree(ek);
return NULL;
}
return &ek->sshk;
}
#define eddsa_generate eddsa_generate_wrapper
#define VALTYPE_TYPEDEF(n,t,f) \
typedef t TD_val_##n; \
typedef t *TD_out_val_##n;

Просмотреть файл

@ -228,6 +228,16 @@ FUNC1(void, prng_seed_finish, val_prng)
FUNC2(val_string, prng_read, val_prng, uint)
FUNC3(void, prng_add_entropy, val_prng, uint, val_string_ptrlen)
/*
* Key generation functions.
*/
FUNC1(val_key, rsa_generate, uint)
FUNC1(val_key, dsa_generate, uint)
FUNC1(opt_val_key, ecdsa_generate, uint)
FUNC1(opt_val_key, eddsa_generate, uint)
FUNC1(val_rsa, rsa1_generate, uint)
FUNC5(val_mpint, primegen, uint, uint, uint, val_mpint, uint)
/*
* Miscellaneous.
*/
@ -245,7 +255,6 @@ FUNC1(uint, crc32_rfc1662, val_string_ptrlen)
FUNC1(uint, crc32_ssh1, val_string_ptrlen)
FUNC2(uint, crc32_update, uint, val_string_ptrlen)
FUNC2(boolean, crcda_detect, val_string_ptrlen, val_string_ptrlen)
FUNC5(val_mpint, primegen, uint, uint, uint, val_mpint, uint)
/*
* These functions aren't part of PuTTY's own API, but are additions