Project

General

Profile

Feature #13681 ยป add_evp_init_to_digests.patch

rinzler (Colton Jenkins), 06/27/2017 02:26 AM

View differences:

new/ext/digest/digest.h 2017-06-21 12:56:32.458975554 -0400
rb_digest_hash_finish_func_t finish_func;
} rb_digest_metadata_t;
#define DEFINE_INIT_FUNC_FOR_EVP(upper_name, lower_name) \
int \
rb_digest_##upper_name##_evp_init(upper_name##_CTX* ctx) \
{ \
SSL_load_error_strings(); \
EVP_MD_CTX *md_ctx = EVP_MD_CTX_create(); \
\
if(!EVP_DigestInit_ex(md_ctx, EVP_##lower_name(), NULL)) { \
const char *error_message; \
EVP_MD_CTX_destroy(md_ctx); \
\
error_message = ERR_reason_error_string(ERR_peek_last_error()); \
rb_raise(rb_eRuntimeError, error_message); \
} \
*ctx = *(upper_name##_CTX*)md_ctx->md_data; \
EVP_MD_CTX_destroy(md_ctx); \
\
return 1; \
}
#define DEFINE_UPDATE_FUNC_FOR_UINT(name) \
void \
rb_digest_##name##_update(void *ctx, unsigned char *ptr, size_t size) \
new/ext/digest/md5/md5ossl.h 2017-06-21 12:56:32.458975554 -0400
#include <stddef.h>
#include <openssl/md5.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#define MD5_BLOCK_LENGTH MD5_CBLOCK
static DEFINE_INIT_FUNC_FOR_EVP(MD5, md5)
#undef MD5_Init
#define MD5_Init rb_digest_MD5_evp_init
static DEFINE_FINISH_FUNC_FROM_FINAL(MD5)
#undef MD5_Finish
#define MD5_Finish rb_digest_MD5_finish
new/ext/digest/rmd160/rmd160ossl.h 2017-06-21 12:56:32.458975554 -0400
#include <stddef.h>
#include <openssl/ripemd.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#define RMD160_CTX RIPEMD160_CTX
......
#define RMD160_BLOCK_LENGTH RIPEMD160_CBLOCK
#define RMD160_DIGEST_LENGTH RIPEMD160_DIGEST_LENGTH
static DEFINE_INIT_FUNC_FOR_EVP(RIPEMD160, ripemd160)
#undef RMD160_Init
#define RMD160_Init rb_digest_RIPEMD160_evp_init
static DEFINE_FINISH_FUNC_FROM_FINAL(RIPEMD160)
#define RMD160_Finish rb_digest_RIPEMD160_finish
new/ext/digest/sha1/sha1ossl.h 2017-06-21 12:56:32.458975554 -0400
#include <stddef.h>
#include <openssl/sha.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#define SHA1_CTX SHA_CTX
......
#endif
#define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH
static DEFINE_INIT_FUNC_FOR_EVP(SHA1, sha1)
#undef SHA1_Init
#define SHA1_Init rb_digest_SHA1_evp_init
static DEFINE_FINISH_FUNC_FROM_FINAL(SHA1)
#undef SHA1_Finish
#define SHA1_Finish rb_digest_SHA1_finish
new/ext/digest/sha2/sha2ossl.h 2017-06-21 12:56:32.458975554 -0400
#include <stddef.h>
#include <openssl/sha.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#define SHA256_BLOCK_LENGTH SHA256_CBLOCK
#define SHA384_BLOCK_LENGTH SHA512_CBLOCK
......
typedef SHA512_CTX SHA384_CTX;
#undef SHA256_Init
#undef SHA384_Init
#undef SHA512_Init
#define SHA256_Init rb_digest_SHA256_evp_init
#define SHA384_Init rb_digest_SHA384_evp_init
#define SHA512_Init rb_digest_SHA512_evp_init
static DEFINE_INIT_FUNC_FOR_EVP(SHA256, sha256)
static DEFINE_INIT_FUNC_FOR_EVP(SHA384, sha384)
static DEFINE_INIT_FUNC_FOR_EVP(SHA512, sha512)
#undef SHA256_Finish
#undef SHA384_Finish
#undef SHA512_Finish
    (1-1/1)