diff options
author | Matt Johnston <matt@ucc.asn.au> | 2010-07-21 12:55:25 +0000 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2010-07-21 12:55:25 +0000 |
commit | 2f797b76992ce382d13a229cb0882e060cd297fc (patch) | |
tree | 6959f8ef7d3488ab5e198de958fbf52467218097 | |
parent | 4bdf1aa1eb8e4fb38a8b3f6693e110397712bf5e (diff) | |
download | dropbear-2f797b76992ce382d13a229cb0882e060cd297fc.tar.gz |
Rename rsa_key to dropbear_rsa_key (and same for dss too) so
we don't conflict with libtomcrypt.
-rw-r--r-- | dss.c | 14 | ||||
-rw-r--r-- | dss.h | 20 | ||||
-rw-r--r-- | gendss.c | 26 | ||||
-rw-r--r-- | gendss.h | 2 | ||||
-rw-r--r-- | genrsa.c | 6 | ||||
-rw-r--r-- | genrsa.h | 2 | ||||
-rw-r--r-- | rsa.c | 18 | ||||
-rw-r--r-- | rsa.h | 20 | ||||
-rw-r--r-- | signkey.c | 8 | ||||
-rw-r--r-- | signkey.h | 4 |
10 files changed, 58 insertions, 62 deletions
@@ -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 @@ int buf_get_dss_pub_key(buffer* buf, dss_key *key) { /* 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 @@ int buf_get_dss_priv_key(buffer* buf, dss_key *key) { /* 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 @@ void dss_key_free(dss_key *key) { * 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 @@ void buf_put_dss_pub_key(buffer* buf, dss_key *key) { } /* 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 @@ void buf_put_dss_priv_key(buffer* buf, dss_key *key) { #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 @@ static unsigned char* mptobytes(mp_int *mp, int *len) { * * 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]; @@ -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 @@ struct DSS_key { /* 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 */ @@ -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 @@ dss_key * gen_dss_priv_key(unsigned int size) { } -static void getq(dss_key *key) { +static void getq(dropbear_dss_key *key) { char buf[QSIZE]; @@ -86,7 +86,7 @@ static void getq(dss_key *key) { } } -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 @@ static void getp(dss_key *key, unsigned int size) { 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 @@ static void getg(dss_key * key) { 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"); @@ -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 */ @@ -37,14 +37,14 @@ static void getrsaprime(mp_int* prime, mp_int *primeminus, 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)); @@ -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 */ @@ -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 @@ static void rsa_pad_em(rsa_key * key, * 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 @@ out: /* 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 @@ out: /* 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 @@ void rsa_key_free(rsa_key *key) { * 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 @@ void buf_put_rsa_pub_key(buffer* buf, rsa_key *key) { } /* 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 @@ void buf_put_rsa_priv_key(buffer* buf, rsa_key *key) { #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 @@ out: /* 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 @@ void buf_put_rsa_sign(buffer* buf, rsa_key *key, const unsigned char* data, * * 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) { @@ -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 @@ struct RSA_key { 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 */ @@ -119,7 +119,7 @@ int buf_get_pub_key(buffer *buf, sign_key *key, int *type) { #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 @@ int buf_get_pub_key(buffer *buf, sign_key *key, int *type) { #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 @@ int buf_get_priv_key(buffer *buf, sign_key *key, int *type) { #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 @@ int buf_get_priv_key(buffer *buf, sign_key *key, int *type) { #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); @@ -46,10 +46,10 @@ struct SIGN_key { * the private key portion */ #ifdef DROPBEAR_DSS - dss_key * dsskey; + dropbear_dss_key * dsskey; #endif #ifdef DROPBEAR_RSA - rsa_key * rsakey; + dropbear_rsa_key * rsakey; #endif }; |