Mercurial > dropbear
changeset 586:b50f0107e505
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
we don't conflict with libtomcrypt.
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 21 Jul 2010 12:55:25 +0000 |
parents | d194db6f9453 |
children | 1151059c5eff |
files | dss.c dss.h gendss.c gendss.h genrsa.c genrsa.h rsa.c rsa.h signkey.c signkey.h |
diffstat | 10 files changed, 58 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/dss.c Wed Jul 21 12:38:46 2010 +0000 +++ b/dss.c Wed Jul 21 12:55:25 2010 +0000 @@ -43,7 +43,7 @@ * The key will have the same format as buf_put_dss_key. * These should be freed with dss_key_free. * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ -int buf_get_dss_pub_key(buffer* buf, dss_key *key) { +int buf_get_dss_pub_key(buffer* buf, dropbear_dss_key *key) { TRACE(("enter buf_get_dss_pub_key")) dropbear_assert(key != NULL); @@ -76,7 +76,7 @@ /* Same as buf_get_dss_pub_key, but reads a private "x" key at the end. * Loads a private dss key from a buffer * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ -int buf_get_dss_priv_key(buffer* buf, dss_key *key) { +int buf_get_dss_priv_key(buffer* buf, dropbear_dss_key *key) { int ret = DROPBEAR_FAILURE; @@ -99,7 +99,7 @@ /* Clear and free the memory used by a public or private key */ -void dss_key_free(dss_key *key) { +void dss_key_free(dropbear_dss_key *key) { TRACE(("enter dsa_key_free")) if (key == NULL) { @@ -138,7 +138,7 @@ * mpint g * mpint y */ -void buf_put_dss_pub_key(buffer* buf, dss_key *key) { +void buf_put_dss_pub_key(buffer* buf, dropbear_dss_key *key) { dropbear_assert(key != NULL); buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN); @@ -150,7 +150,7 @@ } /* Same as buf_put_dss_pub_key, but with the private "x" key appended */ -void buf_put_dss_priv_key(buffer* buf, dss_key *key) { +void buf_put_dss_priv_key(buffer* buf, dropbear_dss_key *key) { dropbear_assert(key != NULL); buf_put_dss_pub_key(buf, key); @@ -161,7 +161,7 @@ #ifdef DROPBEAR_SIGNKEY_VERIFY /* Verify a DSS signature (in buf) made on data by the key given. * returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ -int buf_dss_verify(buffer* buf, dss_key *key, const unsigned char* data, +int buf_dss_verify(buffer* buf, dropbear_dss_key *key, const unsigned char* data, unsigned int len) { unsigned char msghash[SHA1_HASH_SIZE]; @@ -292,7 +292,7 @@ * * Now we aren't relying on the random number generation to protect the private * key x, which is a long term secret */ -void buf_put_dss_sign(buffer* buf, dss_key *key, const unsigned char* data, +void buf_put_dss_sign(buffer* buf, dropbear_dss_key *key, const unsigned char* data, unsigned int len) { unsigned char msghash[SHA1_HASH_SIZE];
--- a/dss.h Wed Jul 21 12:38:46 2010 +0000 +++ b/dss.h Wed Jul 21 12:55:25 2010 +0000 @@ -32,7 +32,7 @@ #define DSS_SIGNATURE_SIZE 4+SSH_SIGNKEY_DSS_LEN+4+2*SHA1_HASH_SIZE -struct DSS_key { +typedef struct { mp_int* p; mp_int* q; @@ -41,21 +41,19 @@ /* x is the private part */ mp_int* x; -}; +} dropbear_dss_key; -typedef struct DSS_key dss_key; - -void buf_put_dss_sign(buffer* buf, dss_key *key, const unsigned char* data, +void buf_put_dss_sign(buffer* buf, dropbear_dss_key *key, const unsigned char* data, unsigned int len); #ifdef DROPBEAR_SIGNKEY_VERIFY -int buf_dss_verify(buffer* buf, dss_key *key, const unsigned char* data, +int buf_dss_verify(buffer* buf, dropbear_dss_key *key, const unsigned char* data, unsigned int len); #endif -int buf_get_dss_pub_key(buffer* buf, dss_key *key); -int buf_get_dss_priv_key(buffer* buf, dss_key *key); -void buf_put_dss_pub_key(buffer* buf, dss_key *key); -void buf_put_dss_priv_key(buffer* buf, dss_key *key); -void dss_key_free(dss_key *key); +int buf_get_dss_pub_key(buffer* buf, dropbear_dss_key *key); +int buf_get_dss_priv_key(buffer* buf, dropbear_dss_key *key); +void buf_put_dss_pub_key(buffer* buf, dropbear_dss_key *key); +void buf_put_dss_priv_key(buffer* buf, dropbear_dss_key *key); +void dss_key_free(dropbear_dss_key *key); #endif /* DROPBEAR_DSS */
--- a/gendss.c Wed Jul 21 12:38:46 2010 +0000 +++ b/gendss.c Wed Jul 21 12:55:25 2010 +0000 @@ -37,17 +37,17 @@ #ifdef DROPBEAR_DSS -static void getq(dss_key *key); -static void getp(dss_key *key, unsigned int size); -static void getg(dss_key *key); -static void getx(dss_key *key); -static void gety(dss_key *key); +static void getq(dropbear_dss_key *key); +static void getp(dropbear_dss_key *key, unsigned int size); +static void getg(dropbear_dss_key *key); +static void getx(dropbear_dss_key *key); +static void gety(dropbear_dss_key *key); -dss_key * gen_dss_priv_key(unsigned int size) { +dropbear_dss_key * gen_dss_priv_key(unsigned int size) { - dss_key *key; + dropbear_dss_key *key; - key = (dss_key*)m_malloc(sizeof(dss_key)); + key = m_malloc(sizeof(*key)); key->p = (mp_int*)m_malloc(sizeof(mp_int)); key->q = (mp_int*)m_malloc(sizeof(mp_int)); @@ -68,7 +68,7 @@ } -static void getq(dss_key *key) { +static void getq(dropbear_dss_key *key) { char buf[QSIZE]; @@ -86,7 +86,7 @@ } } -static void getp(dss_key *key, unsigned int size) { +static void getp(dropbear_dss_key *key, unsigned int size) { DEF_MP_INT(tempX); DEF_MP_INT(tempC); @@ -145,7 +145,7 @@ m_free(buf); } -static void getg(dss_key * key) { +static void getg(dropbear_dss_key * key) { DEF_MP_INT(div); DEF_MP_INT(h); @@ -182,12 +182,12 @@ mp_clear_multi(&div, &h, &val, NULL); } -static void getx(dss_key *key) { +static void getx(dropbear_dss_key *key) { gen_random_mpint(key->q, key->x); } -static void gety(dss_key *key) { +static void gety(dropbear_dss_key *key) { if (mp_exptmod(key->g, key->x, key->p, key->y) != MP_OKAY) { fprintf(stderr, "dss key generation failed\n");
--- a/gendss.h Wed Jul 21 12:38:46 2010 +0000 +++ b/gendss.h Wed Jul 21 12:55:25 2010 +0000 @@ -29,7 +29,7 @@ #ifdef DROPBEAR_DSS -dss_key * gen_dss_priv_key(unsigned int size); +dropbear_dss_key * gen_dss_priv_key(unsigned int size); #endif /* DROPBEAR_DSS */
--- a/genrsa.c Wed Jul 21 12:38:46 2010 +0000 +++ b/genrsa.c Wed Jul 21 12:55:25 2010 +0000 @@ -37,14 +37,14 @@ mp_int* rsa_e, unsigned int size); /* mostly taken from libtomcrypt's rsa key generation routine */ -rsa_key * gen_rsa_priv_key(unsigned int size) { +dropbear_rsa_key * gen_rsa_priv_key(unsigned int size) { - rsa_key * key; + dropbear_rsa_key * key; DEF_MP_INT(pminus); DEF_MP_INT(qminus); DEF_MP_INT(lcm); - key = (rsa_key*)m_malloc(sizeof(rsa_key)); + key = m_malloc(sizeof(*key)); key->e = (mp_int*)m_malloc(sizeof(mp_int)); key->n = (mp_int*)m_malloc(sizeof(mp_int));
--- a/genrsa.h Wed Jul 21 12:38:46 2010 +0000 +++ b/genrsa.h Wed Jul 21 12:55:25 2010 +0000 @@ -29,7 +29,7 @@ #ifdef DROPBEAR_RSA -rsa_key * gen_rsa_priv_key(unsigned int size); +dropbear_rsa_key * gen_rsa_priv_key(unsigned int size); #endif /* DROPBEAR_RSA */
--- a/rsa.c Wed Jul 21 12:38:46 2010 +0000 +++ b/rsa.c Wed Jul 21 12:55:25 2010 +0000 @@ -38,7 +38,7 @@ #ifdef DROPBEAR_RSA -static void rsa_pad_em(rsa_key * key, +static void rsa_pad_em(dropbear_rsa_key * key, const unsigned char * data, unsigned int len, mp_int * rsa_em); @@ -46,7 +46,7 @@ * The key will have the same format as buf_put_rsa_key. * These should be freed with rsa_key_free. * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ -int buf_get_rsa_pub_key(buffer* buf, rsa_key *key) { +int buf_get_rsa_pub_key(buffer* buf, dropbear_rsa_key *key) { int ret = DROPBEAR_FAILURE; TRACE(("enter buf_get_rsa_pub_key")) @@ -84,7 +84,7 @@ /* Same as buf_get_rsa_pub_key, but reads private bits at the end. * Loads a private rsa key from a buffer * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ -int buf_get_rsa_priv_key(buffer* buf, rsa_key *key) { +int buf_get_rsa_priv_key(buffer* buf, dropbear_rsa_key *key) { int ret = DROPBEAR_FAILURE; TRACE(("enter buf_get_rsa_priv_key")) @@ -137,7 +137,7 @@ /* Clear and free the memory used by a public or private key */ -void rsa_key_free(rsa_key *key) { +void rsa_key_free(dropbear_rsa_key *key) { TRACE(("enter rsa_key_free")) @@ -175,7 +175,7 @@ * mp_int e * mp_int n */ -void buf_put_rsa_pub_key(buffer* buf, rsa_key *key) { +void buf_put_rsa_pub_key(buffer* buf, dropbear_rsa_key *key) { TRACE(("enter buf_put_rsa_pub_key")) dropbear_assert(key != NULL); @@ -189,7 +189,7 @@ } /* Same as buf_put_rsa_pub_key, but with the private "x" key appended */ -void buf_put_rsa_priv_key(buffer* buf, rsa_key *key) { +void buf_put_rsa_priv_key(buffer* buf, dropbear_rsa_key *key) { TRACE(("enter buf_put_rsa_priv_key")) @@ -213,7 +213,7 @@ #ifdef DROPBEAR_SIGNKEY_VERIFY /* Verify a signature in buf, made on data by the key given. * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ -int buf_rsa_verify(buffer * buf, rsa_key *key, const unsigned char* data, +int buf_rsa_verify(buffer * buf, dropbear_rsa_key *key, const unsigned char* data, unsigned int len) { unsigned int slen; @@ -270,7 +270,7 @@ /* Sign the data presented with key, writing the signature contents * to the buffer */ -void buf_put_rsa_sign(buffer* buf, rsa_key *key, const unsigned char* data, +void buf_put_rsa_sign(buffer* buf, dropbear_rsa_key *key, const unsigned char* data, unsigned int len) { unsigned int nsize, ssize; @@ -376,7 +376,7 @@ * * rsa_em must be a pointer to an initialised mp_int. */ -static void rsa_pad_em(rsa_key * key, +static void rsa_pad_em(dropbear_rsa_key * key, const unsigned char * data, unsigned int len, mp_int * rsa_em) {
--- a/rsa.h Wed Jul 21 12:38:46 2010 +0000 +++ b/rsa.h Wed Jul 21 12:55:25 2010 +0000 @@ -32,7 +32,7 @@ #define RSA_SIGNATURE_SIZE 4+7+4+40 -struct RSA_key { +typedef struct { mp_int* n; mp_int* e; @@ -41,21 +41,19 @@ mp_int* p; mp_int* q; -}; +} dropbear_rsa_key; -typedef struct RSA_key rsa_key; - -void buf_put_rsa_sign(buffer* buf, rsa_key *key, const unsigned char* data, +void buf_put_rsa_sign(buffer* buf, dropbear_rsa_key *key, const unsigned char* data, unsigned int len); #ifdef DROPBEAR_SIGNKEY_VERIFY -int buf_rsa_verify(buffer * buf, rsa_key *key, const unsigned char* data, +int buf_rsa_verify(buffer * buf, dropbear_rsa_key *key, const unsigned char* data, unsigned int len); #endif -int buf_get_rsa_pub_key(buffer* buf, rsa_key *key); -int buf_get_rsa_priv_key(buffer* buf, rsa_key *key); -void buf_put_rsa_pub_key(buffer* buf, rsa_key *key); -void buf_put_rsa_priv_key(buffer* buf, rsa_key *key); -void rsa_key_free(rsa_key *key); +int buf_get_rsa_pub_key(buffer* buf, dropbear_rsa_key *key); +int buf_get_rsa_priv_key(buffer* buf, dropbear_rsa_key *key); +void buf_put_rsa_pub_key(buffer* buf, dropbear_rsa_key *key); +void buf_put_rsa_priv_key(buffer* buf, dropbear_rsa_key *key); +void rsa_key_free(dropbear_rsa_key *key); #endif /* DROPBEAR_RSA */
--- a/signkey.c Wed Jul 21 12:38:46 2010 +0000 +++ b/signkey.c Wed Jul 21 12:55:25 2010 +0000 @@ -119,7 +119,7 @@ #ifdef DROPBEAR_DSS if (keytype == DROPBEAR_SIGNKEY_DSS) { dss_key_free(key->dsskey); - key->dsskey = (dss_key*)m_malloc(sizeof(dss_key)); + key->dsskey = m_malloc(sizeof(*key->dsskey)); ret = buf_get_dss_pub_key(buf, key->dsskey); if (ret == DROPBEAR_FAILURE) { m_free(key->dsskey); @@ -129,7 +129,7 @@ #ifdef DROPBEAR_RSA if (keytype == DROPBEAR_SIGNKEY_RSA) { rsa_key_free(key->rsakey); - key->rsakey = (rsa_key*)m_malloc(sizeof(rsa_key)); + key->rsakey = m_malloc(sizeof(*key->rsakey)); ret = buf_get_rsa_pub_key(buf, key->rsakey); if (ret == DROPBEAR_FAILURE) { m_free(key->rsakey); @@ -172,7 +172,7 @@ #ifdef DROPBEAR_DSS if (keytype == DROPBEAR_SIGNKEY_DSS) { dss_key_free(key->dsskey); - key->dsskey = (dss_key*)m_malloc(sizeof(dss_key)); + key->dsskey = m_malloc(sizeof(*key->dsskey)); ret = buf_get_dss_priv_key(buf, key->dsskey); if (ret == DROPBEAR_FAILURE) { m_free(key->dsskey); @@ -182,7 +182,7 @@ #ifdef DROPBEAR_RSA if (keytype == DROPBEAR_SIGNKEY_RSA) { rsa_key_free(key->rsakey); - key->rsakey = (rsa_key*)m_malloc(sizeof(rsa_key)); + key->rsakey = m_malloc(sizeof(*key->rsakey)); ret = buf_get_rsa_priv_key(buf, key->rsakey); if (ret == DROPBEAR_FAILURE) { m_free(key->rsakey);