diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2016-03-09 18:45:40 -0400 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2016-03-09 18:45:40 -0400 |
commit | f2e972d50dd951556af9694ecac9c9a00097e3f3 (patch) | |
tree | 2dd3aa8ae94ba385eb5307356d4c32fcb96dbc65 /src/_cffi_src/openssl | |
parent | 801999fe6ba5391b098a20047d7f2644c57bcf4c (diff) | |
download | cryptography-f2e972d50dd951556af9694ecac9c9a00097e3f3.tar.gz cryptography-f2e972d50dd951556af9694ecac9c9a00097e3f3.tar.bz2 cryptography-f2e972d50dd951556af9694ecac9c9a00097e3f3.zip |
opaque HMAC_CTX, which requires some helper functions
Diffstat (limited to 'src/_cffi_src/openssl')
-rw-r--r-- | src/_cffi_src/openssl/hmac.py | 40 |
1 files changed, 36 insertions, 4 deletions
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 +} """ |