rubysl-digest 2.0.3 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,11 +1,9 @@
1
1
  /*
2
- * sha2.h
2
+ * FILE: sha2.h
3
+ * AUTHOR: Aaron D. Gifford - http://www.aarongifford.com/
3
4
  *
4
- * Version 1.0.0beta1
5
- *
6
- * Written by Aaron D. Gifford <me@aarongifford.com>
7
- *
8
- * Copyright 2000 Aaron D. Gifford. All rights reserved.
5
+ * Copyright (c) 2000-2001, Aaron D. Gifford
6
+ * All rights reserved.
9
7
  *
10
8
  * Redistribution and use in source and binary forms, with or without
11
9
  * modification, are permitted provided that the following conditions
@@ -19,10 +17,10 @@
19
17
  * may be used to endorse or promote products derived from this software
20
18
  * without specific prior written permission.
21
19
  *
22
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTOR(S) ``AS IS'' AND
20
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
23
21
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
22
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE
23
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
26
24
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
25
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28
26
  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@@ -31,11 +29,11 @@
31
29
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32
30
  * SUCH DAMAGE.
33
31
  *
32
+ * $OrigId: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $
33
+ * $RoughId: sha2.h,v 1.3 2002/02/24 08:14:32 knu Exp $
34
+ * $Id$
34
35
  */
35
36
 
36
- /* $RoughId: sha2.h,v 1.3 2002/02/24 08:14:32 knu Exp $ */
37
- /* $Id: sha2.h 11708 2007-02-12 23:01:19Z shyouhei $ */
38
-
39
37
  #ifndef __SHA2_H__
40
38
  #define __SHA2_H__
41
39
 
@@ -43,7 +41,37 @@
43
41
  extern "C" {
44
42
  #endif
45
43
 
46
- #include "defs.h"
44
+
45
+ /*
46
+ * Import u_intXX_t size_t type definitions from system headers. You
47
+ * may need to change this, or define these things yourself in this
48
+ * file.
49
+ */
50
+ #include <sys/types.h>
51
+
52
+ #ifdef RUBY
53
+ # ifdef HAVE_PROTOTYPES
54
+ # undef NOPROTO
55
+ # else
56
+ # define NOPROTO
57
+ # endif /* HAVE_PROTOTYPES */
58
+ # ifndef BYTE_ORDER
59
+ # define LITTLE_ENDIAN 1234
60
+ # define BIG_ENDIAN 4321
61
+ # ifdef WORDS_BIGENDIAN
62
+ # define BYTE_ORDER BIG_ENDIAN
63
+ # else
64
+ # define BYTE_ORDER LITTLE_ENDIAN
65
+ # endif
66
+ # endif /* BYTE_ORDER */
67
+ # define SHA2_USE_INTTYPES_H
68
+ #else /* RUBY */
69
+ #ifdef SHA2_USE_INTTYPES_H
70
+
71
+ #include <inttypes.h>
72
+
73
+ #endif /* SHA2_USE_INTTYPES_H */
74
+ #endif /* RUBY */
47
75
 
48
76
 
49
77
  /*** SHA-256/384/512 Various Length Definitions ***********************/
@@ -59,7 +87,38 @@ extern "C" {
59
87
 
60
88
 
61
89
  /*** SHA-256/384/512 Context Structures *******************************/
90
+ /* NOTE: If your architecture does not define either u_intXX_t types or
91
+ * uintXX_t (from inttypes.h), you may need to define things by hand
92
+ * for your system:
93
+ */
94
+ #ifndef SHA2_USE_INTTYPES_H
95
+ # ifdef HAVE_U_INT8_T
96
+ typedef u_int8_t uint8_t; /* 1-byte (8-bits) */
97
+ typedef u_int32_t uint32_t; /* 4-bytes (32-bits) */
98
+ typedef u_int64_t uint64_t; /* 8-bytes (64-bits) */
99
+ # else
100
+ typedef unsigned char uint8_t; /* 1-byte (8-bits) */
101
+ typedef unsigned int uint32_t; /* 4-bytes (32-bits) */
102
+ typedef unsigned long long uint64_t; /* 8-bytes (64-bits) */
103
+ # endif
104
+ #endif
62
105
 
106
+ /*
107
+ * Most BSD systems already define u_intXX_t types, as does Linux.
108
+ * Some systems, however, like Compaq's Tru64 Unix instead can use
109
+ * uintXX_t types defined by very recent ANSI C standards and included
110
+ * in the file:
111
+ *
112
+ * #include <inttypes.h>
113
+ *
114
+ * If you choose to use <inttypes.h> then please define:
115
+ *
116
+ * #define SHA2_USE_INTTYPES_H
117
+ *
118
+ * Or on the command line during compile:
119
+ *
120
+ * cc -DSHA2_USE_INTTYPES_H ...
121
+ */
63
122
  typedef struct _SHA256_CTX {
64
123
  uint32_t state[8];
65
124
  uint64_t bitcount;
@@ -74,32 +133,89 @@ typedef struct _SHA512_CTX {
74
133
  typedef SHA512_CTX SHA384_CTX;
75
134
 
76
135
 
136
+ /*** SHA-256/384/512 Function Prototypes ******************************/
77
137
  #ifdef RUBY
78
138
  #define SHA256_Init rb_Digest_SHA256_Init
79
139
  #define SHA256_Update rb_Digest_SHA256_Update
80
140
  #define SHA256_Finish rb_Digest_SHA256_Finish
141
+ #define SHA256_Data rb_Digest_SHA256_Data
142
+ #define SHA256_End rb_Digest_SHA256_End
143
+ #define SHA256_Last rb_Digest_SHA256_Last
144
+ #define SHA256_Transform rb_Digest_SHA256_Transform
145
+ #define SHA256_Final(d, c) SHA256_Finish(c, d)
81
146
 
82
147
  #define SHA384_Init rb_Digest_SHA384_Init
83
148
  #define SHA384_Update rb_Digest_SHA384_Update
84
149
  #define SHA384_Finish rb_Digest_SHA384_Finish
150
+ #define SHA384_Data rb_Digest_SHA384_Data
151
+ #define SHA384_End rb_Digest_SHA384_End
152
+ #define SHA384_Last rb_Digest_SHA384_Last
153
+ #define SHA384_Transform rb_Digest_SHA384_Transform
154
+ #define SHA384_Final(d, c) SHA384_Finish(c, d)
85
155
 
86
156
  #define SHA512_Init rb_Digest_SHA512_Init
87
157
  #define SHA512_Update rb_Digest_SHA512_Update
88
158
  #define SHA512_Finish rb_Digest_SHA512_Finish
89
- #endif
90
-
91
- /*** SHA-256/384/512 Function Prototypes ******************************/
92
- void SHA256_Init _((SHA256_CTX *));
93
- void SHA256_Update _((SHA256_CTX*, const uint8_t*, size_t));
94
- void SHA256_Finish _((SHA256_CTX*, uint8_t[SHA256_DIGEST_LENGTH]));
95
-
96
- void SHA384_Init _((SHA384_CTX*));
97
- void SHA384_Update _((SHA384_CTX*, const uint8_t*, size_t));
98
- void SHA384_Finish _((SHA384_CTX*, uint8_t[SHA384_DIGEST_LENGTH]));
99
-
100
- void SHA512_Init _((SHA512_CTX*));
101
- void SHA512_Update _((SHA512_CTX*, const uint8_t*, size_t));
102
- void SHA512_Finish _((SHA512_CTX*, uint8_t[SHA512_DIGEST_LENGTH]));
159
+ #define SHA512_Data rb_Digest_SHA512_Data
160
+ #define SHA512_End rb_Digest_SHA512_End
161
+ #define SHA512_Last rb_Digest_SHA512_Last
162
+ #define SHA512_Transform rb_Digest_SHA512_Transform
163
+ #define SHA512_Final(d, c) SHA512_Finish(c, d)
164
+ #endif /* RUBY */
165
+
166
+ #ifndef NOPROTO
167
+
168
+ int SHA256_Init(SHA256_CTX *);
169
+ void SHA256_Update(SHA256_CTX*, const uint8_t*, size_t);
170
+ int SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
171
+ char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
172
+ char* SHA256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
173
+
174
+ int SHA384_Init(SHA384_CTX*);
175
+ void SHA384_Update(SHA384_CTX*, const uint8_t*, size_t);
176
+ int SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
177
+ char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
178
+ char* SHA384_Data(const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]);
179
+
180
+ int SHA512_Init(SHA512_CTX*);
181
+ void SHA512_Update(SHA512_CTX*, const uint8_t*, size_t);
182
+ int SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
183
+ char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
184
+ char* SHA512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
185
+
186
+ #else /* NOPROTO */
187
+
188
+ int SHA256_Init();
189
+ void SHA256_Update();
190
+ #ifdef RUBY
191
+ int SHA256_Finish();
192
+ #else
193
+ int SHA256_Final();
194
+ #endif /* RUBY */
195
+ char* SHA256_End();
196
+ char* SHA256_Data();
197
+
198
+ int SHA384_Init();
199
+ void SHA384_Update();
200
+ #ifdef RUBY
201
+ int SHA384_Finish();
202
+ #else
203
+ int SHA384_Final();
204
+ #endif /* RUBY */
205
+ char* SHA384_End();
206
+ char* SHA384_Data();
207
+
208
+ int SHA512_Init();
209
+ void SHA512_Update();
210
+ #ifdef RUBY
211
+ int SHA512_Finish();
212
+ #else
213
+ int SHA512_Final();
214
+ #endif /* RUBY */
215
+ char* SHA512_End();
216
+ char* SHA512_Data();
217
+
218
+ #endif /* NOPROTO */
103
219
 
104
220
  #ifdef __cplusplus
105
221
  }
@@ -0,0 +1,31 @@
1
+ #define COMMON_DIGEST_FOR_OPENSSL 1
2
+ #include <CommonCrypto/CommonDigest.h>
3
+
4
+ #define SHA256_BLOCK_LENGTH CC_SHA256_BLOCK_BYTES
5
+ #define SHA384_BLOCK_LENGTH CC_SHA384_BLOCK_BYTES
6
+ #define SHA512_BLOCK_LENGTH CC_SHA512_BLOCK_BYTES
7
+
8
+ #define SHA384_CTX CC_SHA512_CTX
9
+
10
+ static DEFINE_UPDATE_FUNC_FOR_UINT(SHA256);
11
+ static DEFINE_FINISH_FUNC_FROM_FINAL(SHA256);
12
+ static DEFINE_UPDATE_FUNC_FOR_UINT(SHA384);
13
+ static DEFINE_FINISH_FUNC_FROM_FINAL(SHA384);
14
+ static DEFINE_UPDATE_FUNC_FOR_UINT(SHA512);
15
+ static DEFINE_FINISH_FUNC_FROM_FINAL(SHA512);
16
+
17
+
18
+ #undef SHA256_Update
19
+ #undef SHA256_Finish
20
+ #define SHA256_Update rb_digest_SHA256_update
21
+ #define SHA256_Finish rb_digest_SHA256_finish
22
+
23
+ #undef SHA384_Update
24
+ #undef SHA384_Finish
25
+ #define SHA384_Update rb_digest_SHA384_update
26
+ #define SHA384_Finish rb_digest_SHA384_finish
27
+
28
+ #undef SHA512_Update
29
+ #undef SHA512_Finish
30
+ #define SHA512_Update rb_digest_SHA512_update
31
+ #define SHA512_Finish rb_digest_SHA512_finish
@@ -1,8 +1,14 @@
1
1
  /* $RoughId: sha2init.c,v 1.3 2001/07/13 20:00:43 knu Exp $ */
2
- /* $Id: sha2init.c 19020 2008-09-01 07:48:53Z nobu $ */
2
+ /* $Id$ */
3
3
 
4
4
  #include "digest.h"
5
+ #if defined(SHA2_USE_OPENSSL)
6
+ #include "sha2ossl.h"
7
+ #elif defined(SHA2_USE_COMMONDIGEST)
8
+ #include "sha2cc.h"
9
+ #else
5
10
  #include "sha2.h"
11
+ #endif
6
12
 
7
13
  #define FOREACH_BITLEN(func) func(256) func(384) func(512)
8
14
 
@@ -25,7 +31,7 @@ FOREACH_BITLEN(DEFINE_ALGO_METADATA)
25
31
  * Standards and Technology), described in FIPS PUB 180-2.
26
32
  */
27
33
  void
28
- Init_sha2()
34
+ Init_sha2(void)
29
35
  {
30
36
  VALUE mDigest, cDigest_Base;
31
37
  ID id_metadata;
@@ -35,7 +41,7 @@ Init_sha2()
35
41
 
36
42
  FOREACH_BITLEN(DECLARE_ALGO_CLASS)
37
43
 
38
- id_metadata = rb_intern("metadata");
44
+ id_metadata = rb_intern_const("metadata");
39
45
 
40
46
  mDigest = rb_path2class("Digest");
41
47
  cDigest_Base = rb_path2class("Digest::Base");
@@ -44,7 +50,9 @@ Init_sha2()
44
50
  cDigest_SHA##bitlen = rb_define_class_under(mDigest, "SHA" #bitlen, cDigest_Base); \
45
51
  \
46
52
  rb_ivar_set(cDigest_SHA##bitlen, id_metadata, \
47
- Data_Wrap_Struct(rb_cObject, 0, 0, (void *)&sha##bitlen));
53
+ Data_Wrap_Struct(0, 0, 0, (void *)&sha##bitlen));
48
54
 
55
+ #undef RUBY_UNTYPED_DATA_WARNING
56
+ #define RUBY_UNTYPED_DATA_WARNING 0
49
57
  FOREACH_BITLEN(DEFINE_ALGO_CLASS)
50
58
  }
@@ -0,0 +1,27 @@
1
+ #ifndef SHA2OSSL_H_INCLUDED
2
+ #define SHA2OSSL_H_INCLUDED
3
+
4
+ #include <stddef.h>
5
+ #include <openssl/sha.h>
6
+
7
+ #define SHA256_BLOCK_LENGTH SHA256_CBLOCK
8
+ #define SHA384_BLOCK_LENGTH SHA512_CBLOCK
9
+ #define SHA512_BLOCK_LENGTH SHA512_CBLOCK
10
+
11
+ #ifndef __DragonFly__
12
+ #define SHA384_Final SHA512_Final
13
+ #endif
14
+
15
+ typedef SHA512_CTX SHA384_CTX;
16
+
17
+ #undef SHA256_Finish
18
+ #undef SHA384_Finish
19
+ #undef SHA512_Finish
20
+ #define SHA256_Finish rb_digest_SHA256_finish
21
+ #define SHA384_Finish rb_digest_SHA384_finish
22
+ #define SHA512_Finish rb_digest_SHA512_finish
23
+ static DEFINE_FINISH_FUNC_FROM_FINAL(SHA256);
24
+ static DEFINE_FINISH_FUNC_FROM_FINAL(SHA384);
25
+ static DEFINE_FINISH_FUNC_FROM_FINAL(SHA512);
26
+
27
+ #endif
@@ -0,0 +1,21 @@
1
+ module OpenSSL
2
+ def self.deprecated_warning_flag
3
+ unless flag = (@deprecated_warning_flag ||= nil)
4
+ if try_compile("", flag = "-Werror=deprecated-declarations")
5
+ if with_config("broken-apple-openssl")
6
+ flag = "-Wno-deprecated-declarations"
7
+ end
8
+ $warnflags << " #{flag}"
9
+ else
10
+ flag = ""
11
+ end
12
+ @deprecated_warning_flag = flag
13
+ end
14
+ flag
15
+ end
16
+
17
+ def self.check_func(func, header)
18
+ have_func(func, header, deprecated_warning_flag) and
19
+ have_header(header, nil, deprecated_warning_flag)
20
+ end
21
+ end
data/lib/digest/sha2.rb CHANGED
@@ -7,7 +7,7 @@
7
7
  # All rights reserved. You can redistribute and/or modify it under the same
8
8
  # terms as Ruby.
9
9
  #
10
- # $Id: sha2.rb 11708 2007-02-12 23:01:19Z shyouhei $
10
+ # $Id$
11
11
 
12
12
  require 'digest'
13
13
  require 'digest/sha2/sha2'
@@ -18,9 +18,11 @@ module Digest
18
18
  #
19
19
  class SHA2 < Digest::Class
20
20
  # call-seq:
21
- # Digest::SHA2.new(bitlen = 256) -> digest_obj
21
+ # Digest::SHA2.new(bitlen = 256) -> digest_obj
22
22
  #
23
23
  # Creates a new SHA2 hash object with a given bit length.
24
+ #
25
+ # Valid bit lengths are 256, 384 and 512.
24
26
  def initialize(bitlen = 256)
25
27
  case bitlen
26
28
  when 256
@@ -35,39 +37,70 @@ module Digest
35
37
  @bitlen = bitlen
36
38
  end
37
39
 
38
- # :nodoc:
40
+ # call-seq:
41
+ # digest_obj.reset -> digest_obj
42
+ #
43
+ # Resets the digest to the initial state and returns self.
39
44
  def reset
40
45
  @sha2.reset
41
46
  self
42
47
  end
43
48
 
44
- # :nodoc:
49
+ # call-seq:
50
+ # digest_obj.update(string) -> digest_obj
51
+ # digest_obj << string -> digest_obj
52
+ #
53
+ # Updates the digest using a given _string_ and returns self.
45
54
  def update(str)
46
55
  @sha2.update(str)
47
56
  self
48
57
  end
49
58
  alias << update
50
59
 
51
- def finish
60
+ def finish # :nodoc:
52
61
  @sha2.digest!
53
62
  end
54
63
  private :finish
55
64
 
65
+
66
+ # call-seq:
67
+ # digest_obj.block_length -> Integer
68
+ #
69
+ # Returns the block length of the digest in bytes.
70
+ #
71
+ # Digest::SHA256.new.block_length * 8
72
+ # # => 512
73
+ # Digest::SHA384.new.block_length * 8
74
+ # # => 1024
75
+ # Digest::SHA512.new.block_length * 8
76
+ # # => 1024
56
77
  def block_length
57
78
  @sha2.block_length
58
79
  end
59
80
 
81
+ # call-seq:
82
+ # digest_obj.digest_length -> Integer
83
+ #
84
+ # Returns the length of the hash value of the digest in bytes.
85
+ #
86
+ # Digest::SHA256.new.digest_length * 8
87
+ # # => 256
88
+ # Digest::SHA384.new.digest_length * 8
89
+ # # => 384
90
+ # Digest::SHA512.new.digest_length * 8
91
+ # # => 512
92
+ #
93
+ # For example, digests produced by Digest::SHA256 will always be 32 bytes
94
+ # (256 bits) in size.
60
95
  def digest_length
61
96
  @sha2.digest_length
62
97
  end
63
98
 
64
- # :nodoc:
65
- def initialize_copy(other)
99
+ def initialize_copy(other) # :nodoc:
66
100
  @sha2 = other.instance_eval { @sha2.clone }
67
101
  end
68
102
 
69
- # :nodoc:
70
- def inspect
103
+ def inspect # :nodoc:
71
104
  "#<%s:%d %s>" % [self.class.name, @bitlen, hexdigest]
72
105
  end
73
106
  end