diff options
Diffstat (limited to 'src/_cffi_src')
| -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 +}  """  | 
