Loading src/common/crypto.c +129 −76 Original line number Diff line number Diff line Loading @@ -826,6 +826,60 @@ int crypto_SHA_digest(const unsigned char *m, int len, unsigned char *digest) return (SHA1(m,len,digest) == NULL); } struct crypto_digest_env_t { SHA_CTX d; }; crypto_digest_env_t * crypto_digest_new_env(int type) { assert(type == CRYPTO_SHA1_DIGEST); crypto_digest_env_t *r = tor_malloc(sizeof(crypto_digest_env_t)); SHA1_Init(&r->d); return r; } void crypto_digest_free(crypto_digest_env_t *digest) { assert(digest); tor_free(digest); } void crypto_digest_add_bytes(crypto_digest_env_t *digest, const char *data, size_t len) { assert(digest); assert(data); SHA1_Update(&digest->d, (void*)data, len); } void crypto_digest_get_digest(crypto_digest_env_t *digest, char *out, size_t out_len) { static char r[SHA_DIGEST_LENGTH]; assert(digest && out); assert(out_len <= SHA_DIGEST_LENGTH); SHA1_Final(r, &digest->d); memcpy(out, r, out_len); } crypto_digest_env_t * crypto_digest_copy(const crypto_digest_env_t *digest) { crypto_digest_env_t *r; assert(digest); r = tor_malloc(sizeof(crypto_digest_env_t)); memcpy(r,digest,sizeof(crypto_digest_env_t)); } void crypto_digest_assign(crypto_digest_env_t *into, const crypto_digest_env_t *from) { assert(into && from); memcpy(into,from,sizeof(crypto_digest_env_t)); } /* DH */ static BIGNUM *dh_param_p = NULL; static BIGNUM *dh_param_g = NULL; Loading Loading @@ -1069,4 +1123,3 @@ base64_decode(char *dest, int destlen, const char *src, int srclen) ret += len; return ret; } src/common/crypto.h +14 −2 Original line number Diff line number Diff line Loading @@ -18,8 +18,11 @@ #define CRYPTO_PK_RSA 0 #define CRYPTO_SHA1_DIGEST 0 typedef struct crypto_pk_env_t crypto_pk_env_t; typedef struct crypto_cipher_env_t crypto_cipher_env_t; typedef struct crypto_digest_env_t crypto_digest_env_t; /* global state */ int crypto_global_init(); Loading Loading @@ -96,6 +99,15 @@ crypto_cipher_env_t *crypto_create_init_cipher(int cipher_type, char *key, char /* SHA-1 */ int crypto_SHA_digest(const unsigned char *m, int len, unsigned char *digest); crypto_digest_env_t *crypto_new_digest_env(int type); void crypto_digest_free(crypto_digest_env_t *digest); void crypto_digest_add_bytes(crypto_digest_env_t *digest, const char *data, size_t len); void crypto_digest_get_digest(crypto_digest_env_t *digest, char *out, size_t out_len); crypto_digest_env_t *crypto_digest_copy(const crypto_digest_env_t *digest); void crypto_digest_assign(crypto_digest_env_t *into, const crypto_digest_env_t *from); /* random numbers */ int crypto_seed_rng(); Loading Loading
src/common/crypto.c +129 −76 Original line number Diff line number Diff line Loading @@ -826,6 +826,60 @@ int crypto_SHA_digest(const unsigned char *m, int len, unsigned char *digest) return (SHA1(m,len,digest) == NULL); } struct crypto_digest_env_t { SHA_CTX d; }; crypto_digest_env_t * crypto_digest_new_env(int type) { assert(type == CRYPTO_SHA1_DIGEST); crypto_digest_env_t *r = tor_malloc(sizeof(crypto_digest_env_t)); SHA1_Init(&r->d); return r; } void crypto_digest_free(crypto_digest_env_t *digest) { assert(digest); tor_free(digest); } void crypto_digest_add_bytes(crypto_digest_env_t *digest, const char *data, size_t len) { assert(digest); assert(data); SHA1_Update(&digest->d, (void*)data, len); } void crypto_digest_get_digest(crypto_digest_env_t *digest, char *out, size_t out_len) { static char r[SHA_DIGEST_LENGTH]; assert(digest && out); assert(out_len <= SHA_DIGEST_LENGTH); SHA1_Final(r, &digest->d); memcpy(out, r, out_len); } crypto_digest_env_t * crypto_digest_copy(const crypto_digest_env_t *digest) { crypto_digest_env_t *r; assert(digest); r = tor_malloc(sizeof(crypto_digest_env_t)); memcpy(r,digest,sizeof(crypto_digest_env_t)); } void crypto_digest_assign(crypto_digest_env_t *into, const crypto_digest_env_t *from) { assert(into && from); memcpy(into,from,sizeof(crypto_digest_env_t)); } /* DH */ static BIGNUM *dh_param_p = NULL; static BIGNUM *dh_param_g = NULL; Loading Loading @@ -1069,4 +1123,3 @@ base64_decode(char *dest, int destlen, const char *src, int srclen) ret += len; return ret; }
src/common/crypto.h +14 −2 Original line number Diff line number Diff line Loading @@ -18,8 +18,11 @@ #define CRYPTO_PK_RSA 0 #define CRYPTO_SHA1_DIGEST 0 typedef struct crypto_pk_env_t crypto_pk_env_t; typedef struct crypto_cipher_env_t crypto_cipher_env_t; typedef struct crypto_digest_env_t crypto_digest_env_t; /* global state */ int crypto_global_init(); Loading Loading @@ -96,6 +99,15 @@ crypto_cipher_env_t *crypto_create_init_cipher(int cipher_type, char *key, char /* SHA-1 */ int crypto_SHA_digest(const unsigned char *m, int len, unsigned char *digest); crypto_digest_env_t *crypto_new_digest_env(int type); void crypto_digest_free(crypto_digest_env_t *digest); void crypto_digest_add_bytes(crypto_digest_env_t *digest, const char *data, size_t len); void crypto_digest_get_digest(crypto_digest_env_t *digest, char *out, size_t out_len); crypto_digest_env_t *crypto_digest_copy(const crypto_digest_env_t *digest); void crypto_digest_assign(crypto_digest_env_t *into, const crypto_digest_env_t *from); /* random numbers */ int crypto_seed_rng(); Loading