rubysl-digest 2.0.3 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -10
  3. data/MRI_LICENSE +56 -0
  4. data/ext/rubysl/digest/bubblebabble/bubblebabble.c +27 -28
  5. data/ext/rubysl/digest/defs.h +1 -1
  6. data/ext/rubysl/digest/digest.c +142 -58
  7. data/ext/rubysl/digest/digest.h +25 -5
  8. data/ext/rubysl/digest/digest_conf.rb +28 -0
  9. data/ext/rubysl/digest/extconf.rb +1 -1
  10. data/ext/rubysl/digest/md5/extconf.rb +3 -13
  11. data/ext/rubysl/digest/md5/md5.c +9 -7
  12. data/ext/rubysl/digest/md5/md5.h +3 -3
  13. data/ext/rubysl/digest/md5/md5cc.h +12 -0
  14. data/ext/rubysl/digest/md5/md5init.c +12 -5
  15. data/ext/rubysl/digest/md5/md5ossl.h +4 -2
  16. data/ext/rubysl/digest/rmd160/extconf.rb +3 -12
  17. data/ext/rubysl/digest/rmd160/rmd160.c +12 -6
  18. data/ext/rubysl/digest/rmd160/rmd160.h +3 -3
  19. data/ext/rubysl/digest/rmd160/rmd160init.c +10 -5
  20. data/ext/rubysl/digest/rmd160/rmd160ossl.h +3 -2
  21. data/ext/rubysl/digest/sha1/extconf.rb +3 -12
  22. data/ext/rubysl/digest/sha1/sha1.c +5 -3
  23. data/ext/rubysl/digest/sha1/sha1.h +3 -3
  24. data/ext/rubysl/digest/sha1/sha1cc.h +14 -0
  25. data/ext/rubysl/digest/sha1/sha1init.c +12 -5
  26. data/ext/rubysl/digest/sha1/sha1ossl.h +4 -2
  27. data/ext/rubysl/digest/sha2/extconf.rb +7 -8
  28. data/ext/rubysl/digest/sha2/sha2.c +235 -73
  29. data/ext/rubysl/digest/sha2/sha2.h +142 -26
  30. data/ext/rubysl/digest/sha2/sha2cc.h +31 -0
  31. data/ext/rubysl/digest/sha2/sha2init.c +12 -4
  32. data/ext/rubysl/digest/sha2/sha2ossl.h +27 -0
  33. data/ext/rubysl/openssl/deprecation.rb +21 -0
  34. data/lib/digest/sha2.rb +42 -9
  35. data/lib/rubysl/digest/digest.rb +27 -7
  36. data/lib/rubysl/digest/version.rb +1 -1
  37. data/spec/fixtures/dir/common.rb +171 -0
  38. data/spec/md5/file_spec.rb +1 -1
  39. data/spec/sha1/file_spec.rb +1 -1
  40. data/spec/sha256/file_spec.rb +1 -1
  41. data/spec/sha384/file_spec.rb +1 -1
  42. data/spec/sha512/file_spec.rb +1 -1
  43. data/spec/shared/file/read.rb +21 -0
  44. metadata +15 -5
  45. data/ext/rubysl/digest/bubblebabble/depend +0 -3
  46. data/ext/rubysl/digest/bubblebabble/extconf.h +0 -4
@@ -2,24 +2,25 @@
2
2
 
3
3
  digest.h - header file for ruby digest modules
4
4
 
5
- $Author: shyouhei $
5
+ $Author$
6
6
  created at: Fri May 25 08:54:56 JST 2001
7
7
 
8
8
 
9
9
  Copyright (C) 2001-2006 Akinori MUSHA
10
10
 
11
11
  $RoughId: digest.h,v 1.3 2001/07/13 15:38:27 knu Exp $
12
- $Id: digest.h 11708 2007-02-12 23:01:19Z shyouhei $
12
+ $Id$
13
13
 
14
14
  ************************************************/
15
15
 
16
16
  #include "ruby.h"
17
+ #include "ruby/encoding.h"
17
18
 
18
- #define RUBY_DIGEST_API_VERSION 2
19
+ #define RUBY_DIGEST_API_VERSION 3
19
20
 
20
- typedef void (*rb_digest_hash_init_func_t)(void *);
21
+ typedef int (*rb_digest_hash_init_func_t)(void *);
21
22
  typedef void (*rb_digest_hash_update_func_t)(void *, unsigned char *, size_t);
22
- typedef void (*rb_digest_hash_finish_func_t)(void *, unsigned char *);
23
+ typedef int (*rb_digest_hash_finish_func_t)(void *, unsigned char *);
23
24
 
24
25
  typedef struct {
25
26
  int api_version;
@@ -30,3 +31,22 @@ typedef struct {
30
31
  rb_digest_hash_update_func_t update_func;
31
32
  rb_digest_hash_finish_func_t finish_func;
32
33
  } rb_digest_metadata_t;
34
+
35
+ #define DEFINE_UPDATE_FUNC_FOR_UINT(name) \
36
+ void \
37
+ rb_digest_##name##_update(void *ctx, unsigned char *ptr, size_t size) \
38
+ { \
39
+ const unsigned int stride = 16384; \
40
+ \
41
+ for (; size > stride; size -= stride, ptr += stride) { \
42
+ name##_Update(ctx, ptr, stride); \
43
+ } \
44
+ if (size > 0) name##_Update(ctx, ptr, size); \
45
+ }
46
+
47
+ #define DEFINE_FINISH_FUNC_FROM_FINAL(name) \
48
+ int \
49
+ rb_digest_##name##_finish(void *ctx, unsigned char *ptr) \
50
+ { \
51
+ return name##_Final(ptr, ctx); \
52
+ }
@@ -0,0 +1,28 @@
1
+ def digest_conf(name, hdr = name, funcs = nil)
2
+ unless with_config("bundled-#{name}")
3
+ cc = with_config("common-digest")
4
+ if cc == true or /\b#{name}\b/ =~ cc
5
+ if File.exist?("#$srcdir/#{name}cc.h") and
6
+ have_header("CommonCrypto/CommonDigest.h")
7
+ $defs << "-D#{name.upcase}_USE_COMMONDIGEST"
8
+ return :commondigest
9
+ end
10
+ end
11
+
12
+ dir_config("openssl")
13
+ pkg_config("openssl")
14
+ require File.expand_path('../../openssl/deprecation', __FILE__)
15
+ if have_library("crypto")
16
+ funcs ||= name.upcase
17
+ funcs = Array(funcs)
18
+ hdr = "openssl/#{hdr}.h"
19
+ if funcs.all? {|func| OpenSSL.check_func("#{func}_Transform", hdr)} &&
20
+ funcs.all? {|func| have_type("#{func}_CTX", hdr)}
21
+ $defs << "-D#{name.upcase}_USE_OPENSSL"
22
+ return :ossl
23
+ end
24
+ end
25
+ end
26
+ $objs << "#{name}.#{$OBJEXT}"
27
+ return
28
+ end
@@ -4,7 +4,7 @@
4
4
  require "mkmf"
5
5
 
6
6
  $INSTALLFILES = {
7
- "digest.h" => "$(RUBYARCHDIR)"
7
+ "digest.h" => "$(HDRDIR)"
8
8
  }
9
9
 
10
10
  create_makefile("digest/digest")
@@ -1,29 +1,19 @@
1
+ # -*- coding: us-ascii -*-
1
2
  # $RoughId: extconf.rb,v 1.3 2001/08/14 19:54:51 knu Exp $
2
3
  # $Id$
3
4
 
4
5
  require "mkmf"
6
+ require File.expand_path("../../digest_conf", __FILE__)
5
7
 
6
8
  $defs << "-DHAVE_CONFIG_H"
7
9
  $INCFLAGS << " -I$(srcdir)/.."
8
10
 
9
11
  $objs = [ "md5init.#{$OBJEXT}" ]
10
12
 
11
- dir_config("openssl")
12
-
13
- if !with_config("bundled-md5") &&
14
- have_library("crypto") && have_header("openssl/md5.h")
15
- $objs << "md5ossl.#{$OBJEXT}"
16
-
17
- else
18
- $objs << "md5.#{$OBJEXT}"
19
- end
13
+ digest_conf("md5")
20
14
 
21
15
  have_header("sys/cdefs.h")
22
16
 
23
- have_header("inttypes.h")
24
-
25
- have_header("unistd.h")
26
-
27
17
  $preload = %w[digest]
28
18
 
29
19
  create_makefile("digest/md5/md5")
@@ -49,10 +49,9 @@
49
49
 
50
50
  /*$OrigId: md5c.c,v 1.2 2001/03/26 08:57:14 matz Exp $ */
51
51
  /*$RoughId: md5.c,v 1.2 2001/07/13 19:48:41 knu Exp $ */
52
- /*$Id: md5.c 18459 2008-08-09 23:15:08Z nobu $ */
52
+ /*$Id$ */
53
53
 
54
54
  #include "md5.h"
55
- #include <string.h>
56
55
 
57
56
  #ifdef TEST
58
57
  /*
@@ -60,8 +59,9 @@
60
59
  * The test program should print out the same values as given in section
61
60
  * A.5 of RFC 1321, reproduced below.
62
61
  */
62
+ #include <string.h>
63
63
  int
64
- main()
64
+ main(void)
65
65
  {
66
66
  static const char *const test[7*2] = {
67
67
  "", "d41d8cd98f00b204e9800998ecf8427e",
@@ -102,7 +102,7 @@ main()
102
102
  #ifdef COMPUTE_T_VALUES
103
103
  #include <math.h>
104
104
  int
105
- main()
105
+ main(void)
106
106
  {
107
107
  int i;
108
108
  for (i = 1; i <= 64; ++i) {
@@ -350,7 +350,7 @@ md5_process(MD5_CTX *pms, const uint8_t *data /*[64]*/)
350
350
  pms->state[3] += d;
351
351
  }
352
352
 
353
- void
353
+ int
354
354
  MD5_Init(MD5_CTX *pms)
355
355
  {
356
356
  pms->count[0] = pms->count[1] = 0;
@@ -358,6 +358,7 @@ MD5_Init(MD5_CTX *pms)
358
358
  pms->state[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;
359
359
  pms->state[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301;
360
360
  pms->state[3] = 0x10325476;
361
+ return 1;
361
362
  }
362
363
 
363
364
  void
@@ -368,7 +369,7 @@ MD5_Update(MD5_CTX *pms, const uint8_t *data, size_t nbytes)
368
369
  size_t offset = (pms->count[0] >> 3) & 63;
369
370
  uint32_t nbits = (uint32_t)(nbytes << 3);
370
371
 
371
- if (nbytes <= 0)
372
+ if (nbytes == 0)
372
373
  return;
373
374
 
374
375
  /* Update the message length. */
@@ -398,7 +399,7 @@ MD5_Update(MD5_CTX *pms, const uint8_t *data, size_t nbytes)
398
399
  memcpy(pms->buffer, p, left);
399
400
  }
400
401
 
401
- void
402
+ int
402
403
  MD5_Finish(MD5_CTX *pms, uint8_t *digest)
403
404
  {
404
405
  static const uint8_t pad[64] = {
@@ -419,4 +420,5 @@ MD5_Finish(MD5_CTX *pms, uint8_t *digest)
419
420
  MD5_Update(pms, data, 8);
420
421
  for (i = 0; i < 16; ++i)
421
422
  digest[i] = (uint8_t)(pms->state[i >> 2] >> ((i & 3) << 3));
423
+ return 1;
422
424
  }
@@ -41,7 +41,7 @@
41
41
 
42
42
  /* $OrigId: md5.h,v 1.2 2001/03/26 08:57:14 matz Exp $ */
43
43
  /* $RoughId: md5.h,v 1.3 2002/02/24 08:14:31 knu Exp $ */
44
- /* $Id: md5.h 11708 2007-02-12 23:01:19Z shyouhei $ */
44
+ /* $Id$ */
45
45
 
46
46
  #ifndef MD5_INCLUDED
47
47
  # define MD5_INCLUDED
@@ -69,9 +69,9 @@ typedef struct md5_state_s {
69
69
  #define MD5_Finish rb_Digest_MD5_Finish
70
70
  #endif
71
71
 
72
- void MD5_Init _((MD5_CTX *pms));
72
+ int MD5_Init _((MD5_CTX *pms));
73
73
  void MD5_Update _((MD5_CTX *pms, const uint8_t *data, size_t nbytes));
74
- void MD5_Finish _((MD5_CTX *pms, uint8_t *digest));
74
+ int MD5_Finish _((MD5_CTX *pms, uint8_t *digest));
75
75
 
76
76
  #define MD5_BLOCK_LENGTH 64
77
77
  #define MD5_DIGEST_LENGTH 16
@@ -0,0 +1,12 @@
1
+ #define COMMON_DIGEST_FOR_OPENSSL 1
2
+ #include <CommonCrypto/CommonDigest.h>
3
+
4
+ #define MD5_BLOCK_LENGTH CC_MD5_BLOCK_BYTES
5
+
6
+ static DEFINE_UPDATE_FUNC_FOR_UINT(MD5);
7
+ static DEFINE_FINISH_FUNC_FROM_FINAL(MD5);
8
+
9
+ #undef MD5_Update
10
+ #undef MD5_Finish
11
+ #define MD5_Update rb_digest_MD5_update
12
+ #define MD5_Finish rb_digest_MD5_finish
@@ -1,9 +1,11 @@
1
1
  /* $RoughId: md5init.c,v 1.2 2001/07/13 19:49:10 knu Exp $ */
2
- /* $Id: md5init.c 19020 2008-09-01 07:48:53Z nobu $ */
2
+ /* $Id$ */
3
3
 
4
4
  #include "digest.h"
5
- #if defined(HAVE_OPENSSL_MD5_H)
5
+ #if defined(MD5_USE_OPENSSL)
6
6
  #include "md5ossl.h"
7
+ #elif defined(MD5_USE_COMMONDIGEST)
8
+ #include "md5cc.h"
7
9
  #else
8
10
  #include "md5.h"
9
11
  #endif
@@ -24,15 +26,20 @@ static const rb_digest_metadata_t md5 = {
24
26
  * RFC1321.
25
27
  */
26
28
  void
27
- Init_md5()
29
+ Init_md5(void)
28
30
  {
29
31
  VALUE mDigest, cDigest_Base, cDigest_MD5;
30
32
 
33
+ #if 0
34
+ mDigest = rb_define_module("Digest"); /* let rdoc know */
35
+ #endif
31
36
  mDigest = rb_path2class("Digest");
32
37
  cDigest_Base = rb_path2class("Digest::Base");
33
38
 
34
39
  cDigest_MD5 = rb_define_class_under(mDigest, "MD5", cDigest_Base);
35
40
 
36
- rb_ivar_set(cDigest_MD5, rb_intern("metadata"),
37
- Data_Wrap_Struct(rb_cObject, 0, 0, (void *)&md5));
41
+ #undef RUBY_UNTYPED_DATA_WARNING
42
+ #define RUBY_UNTYPED_DATA_WARNING 0
43
+ rb_iv_set(cDigest_MD5, "metadata",
44
+ Data_Wrap_Struct(0, 0, 0, (void *)&md5));
38
45
  }
@@ -1,4 +1,4 @@
1
- /* $Id: md5ossl.h 11708 2007-02-12 23:01:19Z shyouhei $ */
1
+ /* $Id$ */
2
2
 
3
3
  #ifndef MD5OSSL_H_INCLUDED
4
4
  #define MD5OSSL_H_INCLUDED
@@ -8,6 +8,8 @@
8
8
 
9
9
  #define MD5_BLOCK_LENGTH MD5_CBLOCK
10
10
 
11
- void MD5_Finish(MD5_CTX *pctx, unsigned char *digest);
11
+ static DEFINE_FINISH_FUNC_FROM_FINAL(MD5);
12
+ #undef MD5_Finish
13
+ #define MD5_Finish rb_digest_MD5_finish
12
14
 
13
15
  #endif
@@ -1,28 +1,19 @@
1
+ # -*- coding: us-ascii -*-
1
2
  # $RoughId: extconf.rb,v 1.3 2001/08/14 19:54:51 knu Exp $
2
3
  # $Id$
3
4
 
4
5
  require "mkmf"
6
+ require File.expand_path("../../digest_conf", __FILE__)
5
7
 
6
8
  $defs << "-DNDEBUG" << "-DHAVE_CONFIG_H"
7
9
  $INCFLAGS << " -I$(srcdir)/.."
8
10
 
9
11
  $objs = [ "rmd160init.#{$OBJEXT}" ]
10
12
 
11
- dir_config("openssl")
12
-
13
- if !with_config("bundled-rmd160") &&
14
- have_library("crypto") && have_header("openssl/ripemd.h")
15
- $objs << "rmd160ossl.#{$OBJEXT}"
16
- else
17
- $objs << "rmd160.#{$OBJEXT}"
18
- end
13
+ digest_conf("rmd160", "ripemd", "RIPEMD160")
19
14
 
20
15
  have_header("sys/cdefs.h")
21
16
 
22
- have_header("inttypes.h")
23
-
24
- have_header("unistd.h")
25
-
26
17
  $preload = %w[digest]
27
18
 
28
19
  create_makefile("digest/rmd160/rmd160")
@@ -1,6 +1,6 @@
1
1
  /* $NetBSD: rmd160.c,v 1.1.1.1 2001/03/06 11:21:05 agc Exp $ */
2
2
  /* $RoughId: rmd160.c,v 1.2 2001/07/13 19:49:10 knu Exp $ */
3
- /* $Id: rmd160.c 11708 2007-02-12 23:01:19Z shyouhei $ */
3
+ /* $Id$ */
4
4
 
5
5
  /********************************************************************\
6
6
  *
@@ -124,7 +124,7 @@
124
124
 
125
125
  /********************************************************************/
126
126
 
127
- void
127
+ int
128
128
  RMD160_Init(RMD160_CTX *context)
129
129
  {
130
130
 
@@ -138,6 +138,7 @@ RMD160_Init(RMD160_CTX *context)
138
138
  context->state[4] = 0xc3d2e1f0U;
139
139
  context->length[0] = context->length[1] = 0;
140
140
  context->buflen = 0;
141
+ return 1;
141
142
  }
142
143
 
143
144
  /********************************************************************/
@@ -362,16 +363,20 @@ RMD160_Update(RMD160_CTX *context, const uint8_t *data, size_t nbytes)
362
363
  _DIAGASSERT(data != NULL);
363
364
 
364
365
  /* update length[] */
366
+ #if SIZEOF_SIZE_T * CHAR_BIT > 32
367
+ context->length[1] += (uint32_t)((context->length[0] + nbytes) >> 32);
368
+ #else
365
369
  if (context->length[0] + nbytes < context->length[0])
366
370
  context->length[1]++; /* overflow to msb of length */
367
- context->length[0] += nbytes;
371
+ #endif
372
+ context->length[0] += (uint32_t)nbytes;
368
373
 
369
374
  (void)memset(X, 0, sizeof(X));
370
375
 
371
376
  if ( context->buflen + nbytes < 64 )
372
377
  {
373
378
  (void)memcpy(context->bbuffer + context->buflen, data, nbytes);
374
- context->buflen += nbytes;
379
+ context->buflen += (uint32_t)nbytes;
375
380
  }
376
381
  else
377
382
  {
@@ -401,14 +406,14 @@ RMD160_Update(RMD160_CTX *context, const uint8_t *data, size_t nbytes)
401
406
  /*
402
407
  * Put last bytes from data into context's buffer
403
408
  */
404
- context->buflen = nbytes & 63;
409
+ context->buflen = (uint32_t)nbytes & 63;
405
410
  memcpy(context->bbuffer, data + (64 * i) + ofs, context->buflen);
406
411
  }
407
412
  }
408
413
 
409
414
  /********************************************************************/
410
415
 
411
- void
416
+ int
412
417
  RMD160_Finish(RMD160_CTX *context, uint8_t digest[20])
413
418
  {
414
419
  uint32_t i;
@@ -452,6 +457,7 @@ RMD160_Finish(RMD160_CTX *context, uint8_t digest[20])
452
457
  digest[i + 3] = (context->state[i>>2] >> 24);
453
458
  }
454
459
  }
460
+ return 1;
455
461
  }
456
462
 
457
463
  /************************ end of file rmd160.c **********************/
@@ -1,6 +1,6 @@
1
1
  /* $NetBSD: rmd160.h,v 1.2 2000/07/07 10:47:06 ad Exp $ */
2
2
  /* $RoughId: rmd160.h,v 1.3 2002/02/24 08:14:31 knu Exp $ */
3
- /* $Id: rmd160.h 11708 2007-02-12 23:01:19Z shyouhei $ */
3
+ /* $Id$ */
4
4
 
5
5
  /********************************************************************\
6
6
  *
@@ -43,10 +43,10 @@ typedef struct {
43
43
  #endif
44
44
 
45
45
  __BEGIN_DECLS
46
- void RMD160_Init _((RMD160_CTX *));
46
+ int RMD160_Init _((RMD160_CTX *));
47
47
  void RMD160_Transform _((uint32_t[5], const uint32_t[16]));
48
48
  void RMD160_Update _((RMD160_CTX *, const uint8_t *, size_t));
49
- void RMD160_Finish _((RMD160_CTX *, uint8_t[20]));
49
+ int RMD160_Finish _((RMD160_CTX *, uint8_t[20]));
50
50
  __END_DECLS
51
51
 
52
52
  #define RMD160_BLOCK_LENGTH 64
@@ -1,8 +1,8 @@
1
1
  /* $RoughId: rmd160init.c,v 1.3 2001/07/13 20:00:43 knu Exp $ */
2
- /* $Id: rmd160init.c 19020 2008-09-01 07:48:53Z nobu $ */
2
+ /* $Id$ */
3
3
 
4
4
  #include "digest.h"
5
- #if defined(HAVE_OPENSSL_RIPEMD_H)
5
+ #if defined(RMD160_USE_OPENSSL)
6
6
  #include "rmd160ossl.h"
7
7
  #else
8
8
  #include "rmd160.h"
@@ -24,15 +24,20 @@ static const rb_digest_metadata_t rmd160 = {
24
24
  * Bosselaers, and Bart Preneel.
25
25
  */
26
26
  void
27
- Init_rmd160()
27
+ Init_rmd160(void)
28
28
  {
29
29
  VALUE mDigest, cDigest_Base, cDigest_RMD160;
30
30
 
31
+ #if 0
32
+ mDigest = rb_define_module("Digest"); /* let rdoc know */
33
+ #endif
31
34
  mDigest = rb_path2class("Digest");
32
35
  cDigest_Base = rb_path2class("Digest::Base");
33
36
 
34
37
  cDigest_RMD160 = rb_define_class_under(mDigest, "RMD160", cDigest_Base);
35
38
 
36
- rb_ivar_set(cDigest_RMD160, rb_intern("metadata"),
37
- Data_Wrap_Struct(rb_cObject, 0, 0, (void *)&rmd160));
39
+ #undef RUBY_UNTYPED_DATA_WARNING
40
+ #define RUBY_UNTYPED_DATA_WARNING 0
41
+ rb_iv_set(cDigest_RMD160, "metadata",
42
+ Data_Wrap_Struct(0, 0, 0, (void *)&rmd160));
38
43
  }