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
31 31
    rb_digest_hash_finish_func_t finish_func;
32 32
} rb_digest_metadata_t;
33 33

  
34
#define DEFINE_INIT_FUNC_FOR_EVP(upper_name, lower_name) \
35
int \
36
rb_digest_##upper_name##_evp_init(upper_name##_CTX* ctx) \
37
{ \
38
  SSL_load_error_strings(); \
39
  EVP_MD_CTX *md_ctx = EVP_MD_CTX_create(); \
40
 \
41
  if(!EVP_DigestInit_ex(md_ctx, EVP_##lower_name(), NULL)) { \
42
    const char *error_message; \
43
    EVP_MD_CTX_destroy(md_ctx); \
44
 \
45
    error_message = ERR_reason_error_string(ERR_peek_last_error()); \
46
    rb_raise(rb_eRuntimeError, error_message); \
47
  } \
48
  *ctx = *(upper_name##_CTX*)md_ctx->md_data; \
49
  EVP_MD_CTX_destroy(md_ctx); \
50
 \
51
  return 1; \
52
}
53

  
34 54
#define DEFINE_UPDATE_FUNC_FOR_UINT(name) \
35 55
void \
36 56
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
5 5

  
6 6
#include <stddef.h>
7 7
#include <openssl/md5.h>
8
#include <openssl/ssl.h>
9
#include <openssl/err.h>
8 10

  
9 11
#define MD5_BLOCK_LENGTH	MD5_CBLOCK
10 12

  
13
static DEFINE_INIT_FUNC_FOR_EVP(MD5, md5)
14
#undef MD5_Init
15
#define MD5_Init rb_digest_MD5_evp_init
16

  
11 17
static DEFINE_FINISH_FUNC_FROM_FINAL(MD5)
12 18
#undef MD5_Finish
13 19
#define MD5_Finish rb_digest_MD5_finish
new/ext/digest/rmd160/rmd160ossl.h 2017-06-21 12:56:32.458975554 -0400
5 5

  
6 6
#include <stddef.h>
7 7
#include <openssl/ripemd.h>
8
#include <openssl/ssl.h>
9
#include <openssl/err.h>
8 10

  
9 11
#define RMD160_CTX	RIPEMD160_CTX
10 12

  
......
14 16
#define RMD160_BLOCK_LENGTH		RIPEMD160_CBLOCK
15 17
#define RMD160_DIGEST_LENGTH		RIPEMD160_DIGEST_LENGTH
16 18

  
19
static DEFINE_INIT_FUNC_FOR_EVP(RIPEMD160, ripemd160)
20
#undef RMD160_Init
21
#define RMD160_Init rb_digest_RIPEMD160_evp_init
22

  
17 23
static DEFINE_FINISH_FUNC_FROM_FINAL(RIPEMD160)
18 24
#define RMD160_Finish rb_digest_RIPEMD160_finish
19 25

  
new/ext/digest/sha1/sha1ossl.h 2017-06-21 12:56:32.458975554 -0400
5 5

  
6 6
#include <stddef.h>
7 7
#include <openssl/sha.h>
8
#include <openssl/ssl.h>
9
#include <openssl/err.h>
8 10

  
9 11
#define SHA1_CTX	SHA_CTX
10 12

  
......
15 17
#endif
16 18
#define SHA1_DIGEST_LENGTH	SHA_DIGEST_LENGTH
17 19

  
20
static DEFINE_INIT_FUNC_FOR_EVP(SHA1, sha1)
21
#undef SHA1_Init
22
#define SHA1_Init rb_digest_SHA1_evp_init
23

  
18 24
static DEFINE_FINISH_FUNC_FROM_FINAL(SHA1)
19 25
#undef SHA1_Finish
20 26
#define SHA1_Finish rb_digest_SHA1_finish
new/ext/digest/sha2/sha2ossl.h 2017-06-21 12:56:32.458975554 -0400
3 3

  
4 4
#include <stddef.h>
5 5
#include <openssl/sha.h>
6
#include <openssl/ssl.h>
7
#include <openssl/err.h>
6 8

  
7 9
#define SHA256_BLOCK_LENGTH	SHA256_CBLOCK
8 10
#define SHA384_BLOCK_LENGTH	SHA512_CBLOCK
......
14 16

  
15 17
typedef SHA512_CTX SHA384_CTX;
16 18

  
19
#undef SHA256_Init
20
#undef SHA384_Init
21
#undef SHA512_Init
22
#define SHA256_Init rb_digest_SHA256_evp_init
23
#define SHA384_Init rb_digest_SHA384_evp_init
24
#define SHA512_Init rb_digest_SHA512_evp_init
25
static DEFINE_INIT_FUNC_FOR_EVP(SHA256, sha256)
26
static DEFINE_INIT_FUNC_FOR_EVP(SHA384, sha384)
27
static DEFINE_INIT_FUNC_FOR_EVP(SHA512, sha512)
28

  
17 29
#undef SHA256_Finish
18 30
#undef SHA384_Finish
19 31
#undef SHA512_Finish