From f2e972d50dd951556af9694ecac9c9a00097e3f3 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Wed, 9 Mar 2016 18:45:40 -0400 Subject: opaque HMAC_CTX, which requires some helper functions --- src/_cffi_src/openssl/hmac.py | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src/_cffi_src/openssl') diff --git a/src/_cffi_src/openssl/hmac.py b/src/_cffi_src/openssl/hmac.py index 7178e573..610e32a6 100644 --- a/src/_cffi_src/openssl/hmac.py +++ b/src/_cffi_src/openssl/hmac.py @@ -9,18 +9,17 @@ INCLUDES = """ """ TYPES = """ -typedef struct { ...; } HMAC_CTX; +typedef ... HMAC_CTX; """ FUNCTIONS = """ -void HMAC_CTX_init(HMAC_CTX *); -void HMAC_CTX_cleanup(HMAC_CTX *); - int Cryptography_HMAC_Init_ex(HMAC_CTX *, const void *, int, const EVP_MD *, ENGINE *); int Cryptography_HMAC_Update(HMAC_CTX *, const unsigned char *, size_t); int Cryptography_HMAC_Final(HMAC_CTX *, unsigned char *, unsigned int *); int Cryptography_HMAC_CTX_copy(HMAC_CTX *, HMAC_CTX *); +HMAC_CTX *Cryptography_HMAC_CTX_new(void); +void Cryptography_HMAC_CTX_free(HMAC_CTX *ctx); """ MACROS = """ @@ -80,4 +79,37 @@ int Cryptography_HMAC_CTX_copy(HMAC_CTX *dst_ctx, HMAC_CTX *src_ctx) { return 0; #endif } + +HMAC_CTX *Cryptography_HMAC_CTX_new(void) { +#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) + return HMAC_CTX_new(); +#else + /* This uses OPENSSL_zalloc in 1.1.0, which is malloc + memset */ + HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_malloc(sizeof(HMAC_CTX)); + memset(ctx, 0, sizeof(HMAC_CTX)); + /*if (ctx) + if (!HMAC_CTX_reset(ctx)) { + HMAC_CTX_free(ctx); + ctx = NULL; + }*/ + return ctx; +#endif +} + + + +void Cryptography_HMAC_CTX_free(HMAC_CTX *ctx) { +#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) + return HMAC_CTX_free(ctx); +#else + if (ctx != NULL) { + ctx->md = NULL; + ctx->key_length = 0; + memset(ctx->key, 0, sizeof(HMAC_MAX_MD_CBLOCK)); + + HMAC_CTX_cleanup(ctx); + OPENSSL_free(ctx); + } +#endif +} """ -- cgit v1.2.3 From 851b7f002aaf0781bf1590e8e212c8dff0e25de1 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Thu, 10 Mar 2016 09:37:23 -0400 Subject: simplify HMAC_CTX_free --- src/_cffi_src/openssl/hmac.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/_cffi_src/openssl') diff --git a/src/_cffi_src/openssl/hmac.py b/src/_cffi_src/openssl/hmac.py index 610e32a6..42e5cfb6 100644 --- a/src/_cffi_src/openssl/hmac.py +++ b/src/_cffi_src/openssl/hmac.py @@ -103,10 +103,6 @@ void Cryptography_HMAC_CTX_free(HMAC_CTX *ctx) { return HMAC_CTX_free(ctx); #else if (ctx != NULL) { - ctx->md = NULL; - ctx->key_length = 0; - memset(ctx->key, 0, sizeof(HMAC_MAX_MD_CBLOCK)); - HMAC_CTX_cleanup(ctx); OPENSSL_free(ctx); } -- cgit v1.2.3 From 68b40906e0fa2a3f29521ded880f1620e1a4efeb Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Thu, 10 Mar 2016 09:38:03 -0400 Subject: HMAC_CTX_new doesn't need commented out code for no reason --- src/_cffi_src/openssl/hmac.py | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/_cffi_src/openssl') diff --git a/src/_cffi_src/openssl/hmac.py b/src/_cffi_src/openssl/hmac.py index 42e5cfb6..bcc8a861 100644 --- a/src/_cffi_src/openssl/hmac.py +++ b/src/_cffi_src/openssl/hmac.py @@ -87,11 +87,6 @@ HMAC_CTX *Cryptography_HMAC_CTX_new(void) { /* This uses OPENSSL_zalloc in 1.1.0, which is malloc + memset */ HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_malloc(sizeof(HMAC_CTX)); memset(ctx, 0, sizeof(HMAC_CTX)); - /*if (ctx) - if (!HMAC_CTX_reset(ctx)) { - HMAC_CTX_free(ctx); - ctx = NULL; - }*/ return ctx; #endif } -- cgit v1.2.3