Project

General

Profile

Feature #11625 ยป digest.patch

steved (Steve Dierker), 09/25/2018 11:24 AM

View differences:

ext/digest/digest.c
668 668
    TypedData_Get_Struct(self, void, &digest_type, pctx);
669 669

  
670 670
    StringValue(str);
671
    str = rb_str_new_frozen(str);
671 672
    algo->update_func(pctx, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str));
672 673
    RB_GC_GUARD(str);
673 674

  
ext/digest/md5/md5init.c
2 2
/* $Id$ */
3 3

  
4 4
#include <ruby/ruby.h>
5
#include <ruby/thread.h>
5 6
#include "../digest.h"
6 7
#if defined(MD5_USE_OPENSSL)
7 8
#include "md5ossl.h"
......
11 12
#include "md5.h"
12 13
#endif
13 14

  
15
struct unpack_nogvl {
16
  MD5_CTX *context;
17
  const uint8_t *data;
18
  size_t len;
19
};
20

  
21
void * MD5_UpdateNoGVLUnpack(void * ptr)
22
{
23
  struct unpack_nogvl *args;
24
  args = ptr;
25
  MD5_Update(args->context, args->data, args->len);
26
  return NULL;
27
}
28

  
29
void MD5_UpdateNoGVL(MD5_CTX *context, const uint8_t *data, size_t nbytes)
30
{
31
  struct unpack_nogvl args;
32
  args.context = context;
33
  args.data = data;
34
  args.len = nbytes;
35

  
36
  rb_thread_call_without_gvl(MD5_UpdateNoGVLUnpack, &args, NULL, NULL);
37

  
38
  return;
39
}
40

  
41
struct finish_nogvl {
42
  MD5_CTX *context;
43
  uint8_t *digest;
44
};
45

  
46
void * MD5_FinishNoGvlUnpack(void *ptr)
47
{
48
  struct finish_nogvl *args;
49
  args = ptr;
50
  MD5_Finish(args->context, args->digest);
51
  return NULL;
52
}
53

  
54
int MD5_FinishNoGVL(MD5_CTX *pms, uint8_t *digest)
55
{
56
    struct finish_nogvl args;
57
    args.context = pms;
58
    args.digest = digest;
59

  
60
    rb_thread_call_without_gvl(MD5_FinishNoGvlUnpack, &args, NULL, NULL);
61
    return 1;
62
}
63

  
14 64
static const rb_digest_metadata_t md5 = {
15 65
    RUBY_DIGEST_API_VERSION,
16 66
    MD5_DIGEST_LENGTH,
17 67
    MD5_BLOCK_LENGTH,
18 68
    sizeof(MD5_CTX),
19 69
    (rb_digest_hash_init_func_t)MD5_Init,
20
    (rb_digest_hash_update_func_t)MD5_Update,
21
    (rb_digest_hash_finish_func_t)MD5_Finish,
70
    (rb_digest_hash_update_func_t)MD5_UpdateNoGVL,
71
    (rb_digest_hash_finish_func_t)MD5_FinishNoGVL,
22 72
};
23 73

  
24 74
/*
ext/digest/rmd160/rmd160init.c
2 2
/* $Id$ */
3 3

  
4 4
#include <ruby/ruby.h>
5
#include <ruby/thread.h>
5 6
#include "../digest.h"
6 7
#if defined(RMD160_USE_OPENSSL)
7 8
#include "rmd160ossl.h"
......
9 10
#include "rmd160.h"
10 11
#endif
11 12

  
13
struct unpack_nogvl {
14
  RMD160_CTX *context;
15
  const uint8_t *data;
16
  size_t len;
17
};
18

  
19
void * RMD160_UpdateNoGVLUnpack(void * ptr)
20
{
21
  struct unpack_nogvl *args;
22
  args = ptr;
23
  RMD160_Update(args->context, args->data, args->len);
24
  return NULL;
25
}
26

  
27
void RMD160_UpdateNoGVL(RMD160_CTX *context, const uint8_t *data, size_t nbytes)
28
{
29
  struct unpack_nogvl args;
30
  args.context = context;
31
  args.data = data;
32
  args.len = nbytes;
33

  
34
  rb_thread_call_without_gvl(RMD160_UpdateNoGVLUnpack, &args, NULL, NULL);
35

  
36
  return;
37
}
38

  
39
struct finish_nogvl {
40
  RMD160_CTX *context;
41
  uint8_t *digest;
42
};
43

  
44
void * RMD160_FinishNoGvlUnpack(void *ptr)
45
{
46
  struct finish_nogvl *args;
47
  args = ptr;
48
  RMD160_Finish(args->context, args->digest);
49
  return NULL;
50
}
51

  
52
int RMD160_FinishNoGVL(RMD160_CTX *pms, uint8_t *digest)
53
{
54
    struct finish_nogvl args;
55
    args.context = pms;
56
    args.digest = digest;
57

  
58
    rb_thread_call_without_gvl(RMD160_FinishNoGvlUnpack, &args, NULL, NULL);
59
    return 1;
60
}
61

  
62

  
12 63
static const rb_digest_metadata_t rmd160 = {
13 64
    RUBY_DIGEST_API_VERSION,
14 65
    RMD160_DIGEST_LENGTH,
15 66
    RMD160_BLOCK_LENGTH,
16 67
    sizeof(RMD160_CTX),
17 68
    (rb_digest_hash_init_func_t)RMD160_Init,
18
    (rb_digest_hash_update_func_t)RMD160_Update,
19
    (rb_digest_hash_finish_func_t)RMD160_Finish,
69
    (rb_digest_hash_update_func_t)RMD160_UpdateNoGVL,
70
    (rb_digest_hash_finish_func_t)RMD160_FinishNoGVL,
20 71
};
21 72

  
22 73
/*
ext/digest/sha1/sha1init.c
2 2
/* $Id$ */
3 3

  
4 4
#include <ruby/ruby.h>
5
#include <ruby/thread.h>
5 6
#include "../digest.h"
6 7
#if defined(SHA1_USE_OPENSSL)
7 8
#include "sha1ossl.h"
......
11 12
#include "sha1.h"
12 13
#endif
13 14

  
15
struct unpack_nogvl {
16
  SHA1_CTX *context;
17
  const uint8_t *data;
18
  size_t len;
19
};
20

  
21
void * SHA1_UpdateNoGVLUnpack(void * ptr)
22
{
23
  struct unpack_nogvl *args;
24
  args = ptr;
25
  SHA1_Update(args->context, args->data, args->len);
26
  return NULL;
27
}
28

  
29
void SHA1_UpdateNoGVL(SHA1_CTX *context, const uint8_t *data, size_t nbytes)
30
{
31
  struct unpack_nogvl args;
32
  args.context = context;
33
  args.data = data;
34
  args.len = nbytes;
35

  
36
  rb_thread_call_without_gvl(SHA1_UpdateNoGVLUnpack, &args, NULL, NULL);
37

  
38
  return;
39
}
40

  
41
struct finish_nogvl {
42
  SHA1_CTX *context;
43
  uint8_t *digest;
44
};
45

  
46
void * SHA1_FinishNoGvlUnpack(void *ptr)
47
{
48
  struct finish_nogvl *args;
49
  args = ptr;
50
  SHA1_Finish(args->context, args->digest);
51
  return NULL;
52
}
53

  
54
int SHA1_FinishNoGVL(SHA1_CTX *pms, uint8_t *digest)
55
{
56
    struct finish_nogvl args;
57
    args.context = pms;
58
    args.digest = digest;
59

  
60
    rb_thread_call_without_gvl(SHA1_FinishNoGvlUnpack, &args, NULL, NULL);
61
    return 1;
62
}
14 63
static const rb_digest_metadata_t sha1 = {
15 64
    RUBY_DIGEST_API_VERSION,
16 65
    SHA1_DIGEST_LENGTH,
17 66
    SHA1_BLOCK_LENGTH,
18 67
    sizeof(SHA1_CTX),
19 68
    (rb_digest_hash_init_func_t)SHA1_Init,
20
    (rb_digest_hash_update_func_t)SHA1_Update,
21
    (rb_digest_hash_finish_func_t)SHA1_Finish,
69
    (rb_digest_hash_update_func_t)SHA1_UpdateNoGVL,
70
    (rb_digest_hash_finish_func_t)SHA1_FinishNoGVL,
22 71
};
23 72

  
24 73
/*
ext/digest/sha2/sha2init.c
2 2
/* $Id$ */
3 3

  
4 4
#include <ruby/ruby.h>
5
#include <ruby/thread.h>
5 6
#include "../digest.h"
6 7
#if defined(SHA2_USE_OPENSSL)
7 8
#include "sha2ossl.h"
......
13 14

  
14 15
#define FOREACH_BITLEN(func)	func(256) func(384) func(512)
15 16

  
17
#define DECLARE_NO_GVL_METHODS(bitlen) \
18
struct unpack_##bitlen##_nogvl { \
19
  SHA##bitlen##_CTX *context; \
20
  const uint8_t *data; \
21
  size_t len; \
22
}; \
23
\
24
void * SHA##bitlen##_UpdateNoGVLUnpack(void * ptr) \
25
{ \
26
  struct unpack_##bitlen##_nogvl *args; \
27
  args = ptr; \
28
  SHA##bitlen##_Update(args->context, args->data, args->len); \
29
  return NULL; \
30
} \
31
\
32
void SHA##bitlen##_UpdateNoGVL(SHA##bitlen##_CTX *context, const uint8_t *data, size_t nbytes) \
33
{ \
34
  struct unpack_##bitlen##_nogvl args; \
35
  args.context = context; \
36
  args.data = data; \
37
  args.len = nbytes; \
38
\
39
  rb_thread_call_without_gvl(SHA##bitlen##_UpdateNoGVLUnpack, &args, NULL, NULL); \
40
\
41
  return; \
42
} \
43
\
44
struct finish_##bitlen##_nogvl { \
45
  SHA##bitlen##_CTX *context; \
46
  uint8_t *digest; \
47
}; \
48
\
49
void * SHA##bitlen##_FinishNoGvlUnpack(void *ptr) \
50
{ \
51
  struct finish_##bitlen##_nogvl *args; \
52
  args = ptr; \
53
  SHA##bitlen##_Finish(args->context, args->digest); \
54
  return NULL; \
55
} \
56
\
57
int SHA##bitlen##_FinishNoGVL(SHA##bitlen##_CTX *pms, uint8_t *digest) \
58
{ \
59
    struct finish_##bitlen##_nogvl args; \
60
    args.context = pms; \
61
    args.digest = digest; \
62
\
63
    rb_thread_call_without_gvl(SHA##bitlen##_FinishNoGvlUnpack, &args, NULL, NULL); \
64
    return 1; \
65
}
66

  
67
FOREACH_BITLEN(DECLARE_NO_GVL_METHODS)
68

  
16 69
#define DEFINE_ALGO_METADATA(bitlen) \
17 70
static const rb_digest_metadata_t sha##bitlen = { \
18 71
    RUBY_DIGEST_API_VERSION, \
......
20 73
    SHA##bitlen##_BLOCK_LENGTH, \
21 74
    sizeof(SHA##bitlen##_CTX), \
22 75
    (rb_digest_hash_init_func_t)SHA##bitlen##_Init, \
23
    (rb_digest_hash_update_func_t)SHA##bitlen##_Update, \
24
    (rb_digest_hash_finish_func_t)SHA##bitlen##_Finish, \
76
    (rb_digest_hash_update_func_t)SHA##bitlen##_UpdateNoGVL, \
77
    (rb_digest_hash_finish_func_t)SHA##bitlen##_FinishNoGVL, \
25 78
};
26 79

  
27 80
FOREACH_BITLEN(DEFINE_ALGO_METADATA)