digest-whirlpool 1.0.0

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.
@@ -0,0 +1,142 @@
1
+ /**
2
+ * The Whirlpool hashing function.
3
+ *
4
+ * The Whirlpool algorithm was developed by
5
+ * Paulo S. L. M. Barreto and Vincent Rijmen.
6
+ *
7
+ * See
8
+ * P.S.L.M. Barreto, V. Rijmen,
9
+ * ``The Whirlpool hashing function,''
10
+ * NESSIE submission, 2000 (tweaked version, 2001),
11
+ * <https://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/whirlpool.zip>
12
+ *
13
+ * @version 3.0 (2003.03.12)
14
+ *
15
+ * Modified for use in this software package.
16
+ */
17
+
18
+ #ifndef _WHIRLPOOL_PORTABILITY_H_
19
+ #define _WHIRLPOOL_PORTABILITY_H_
20
+
21
+ /* Definition of minimum-width integer types
22
+ *
23
+ * u8 -> unsigned integer type, at least 8 bits, equivalent to unsigned char
24
+ * u16 -> unsigned integer type, at least 16 bits
25
+ * u32 -> unsigned integer type, at least 32 bits
26
+ *
27
+ * s8, s16, s32 -> signed counterparts of u8, u16, u32
28
+ *
29
+ * Always use macro's T8(), T16() or T32() to obtain exact-width results,
30
+ * i.e., to specify the size of the result of each expression.
31
+ */
32
+
33
+ typedef signed char s8;
34
+ typedef unsigned char u8;
35
+
36
+ #if UINT_MAX >= 4294967295UL
37
+
38
+ typedef signed short s16;
39
+ typedef signed int s32;
40
+ typedef unsigned short u16;
41
+ typedef unsigned int u32;
42
+
43
+ #define ONE32 0xffffffffU
44
+
45
+ #else
46
+
47
+ typedef signed int s16;
48
+ typedef signed long s32;
49
+ typedef unsigned int u16;
50
+ typedef unsigned long u32;
51
+
52
+ #define ONE32 0xffffffffUL
53
+
54
+ #endif
55
+
56
+ #define ONE8 0xffU
57
+ #define ONE16 0xffffU
58
+
59
+ #define T8(x) ((x) & ONE8)
60
+ #define T16(x) ((x) & ONE16)
61
+ #define T32(x) ((x) & ONE32)
62
+
63
+ #ifdef _MSC_VER
64
+ typedef unsigned __int64 u64;
65
+ typedef signed __int64 s64;
66
+ #define LL(v) (v##i64)
67
+ #define ONE64 LL(0xffffffffffffffff)
68
+ #else /* !_MSC_VER */
69
+ typedef unsigned long long u64;
70
+ typedef signed long long s64;
71
+ #define LL(v) (v##ULL)
72
+ #define ONE64 LL(0xffffffffffffffff)
73
+ #endif /* ?_MSC_VER */
74
+ #define T64(x) ((x) & ONE64)
75
+ #define ROTR64(v, n) (((v) >> (n)) | T64((v) << (64 - (n))))
76
+ /*
77
+ * Note: the test is used to detect native 64-bit architectures;
78
+ * if the unsigned long is strictly greater than 32-bit, it is
79
+ * assumed to be at least 64-bit. This will not work correctly
80
+ * on (old) 36-bit architectures (PDP-11 for instance).
81
+ *
82
+ * On non-64-bit architectures, "long long" is used.
83
+ */
84
+
85
+ /*
86
+ * U8TO32_BIG(c) returns the 32-bit value stored in big-endian convention
87
+ * in the unsigned char array pointed to by c.
88
+ */
89
+ #define U8TO32_BIG(c) (((u32)T8(*(c)) << 24) | ((u32)T8(*((c) + 1)) << 16) | ((u32)T8(*((c) + 2)) << 8) | ((u32)T8(*((c) + 3))))
90
+
91
+ /*
92
+ * U8TO32_LITTLE(c) returns the 32-bit value stored in little-endian convention
93
+ * in the unsigned char array pointed to by c.
94
+ */
95
+ #define U8TO32_LITTLE(c) (((u32)T8(*(c))) | ((u32)T8(*((c) + 1)) << 8) | (u32)T8(*((c) + 2)) << 16) | ((u32)T8(*((c) + 3)) << 24))
96
+
97
+ /*
98
+ * U8TO32_BIG(c, v) stores the 32-bit-value v in big-endian convention
99
+ * into the unsigned char array pointed to by c.
100
+ */
101
+ #define U32TO8_BIG(c, v) do { u32 x = (v); u8 *d = (c); d[0] = T8(x >> 24); d[1] = T8(x >> 16); d[2] = T8(x >> 8); d[3] = T8(x); } while (0)
102
+
103
+ /*
104
+ * U8TO32_LITTLE(c, v) stores the 32-bit-value v in little-endian convention
105
+ * into the unsigned char array pointed to by c.
106
+ */
107
+ #define U32TO8_LITTLE(c, v) do { u32 x = (v); u8 *d = (c); d[0] = T8(x); d[1] = T8(x >> 8); d[2] = T8(x >> 16); d[3] = T8(x >> 24); } while (0)
108
+
109
+ /*
110
+ * ROTL32(v, n) returns the value of the 32-bit unsigned value v after
111
+ * a rotation of n bits to the left. It might be replaced by the appropriate
112
+ * architecture-specific macro.
113
+ *
114
+ * It evaluates v and n twice.
115
+ *
116
+ * The compiler might emit a warning if n is the constant 0. The result
117
+ * is undefined if n is greater than 31.
118
+ */
119
+ #define ROTL32(v, n) (T32((v) << (n)) | ((v) >> (32 - (n))))
120
+
121
+ /*
122
+ * Whirlpool-specific definitions.
123
+ */
124
+
125
+ #define DIGESTBYTES WP_DIGEST_SIZE
126
+ #define DIGESTBITS (8*DIGESTBYTES) /* 512 */
127
+
128
+ #define WBLOCKBYTES 64
129
+ #define WBLOCKBITS (8*WBLOCKBYTES) /* 512 */
130
+
131
+ #define LENGTHBYTES 32
132
+ #define LENGTHBITS (8*LENGTHBYTES) /* 256 */
133
+
134
+ struct WP_Struct {
135
+ u8 bitLength[LENGTHBYTES]; /* global number of hashed bits (256-bit counter) */
136
+ u8 buffer[WBLOCKBYTES]; /* buffer of data to hash */
137
+ int bufferBits; /* current number of bits on the buffer */
138
+ int bufferPos; /* current (possibly incomplete) byte slot on the buffer */
139
+ u64 hash[DIGESTBYTES/8]; /* the hashing state */
140
+ };
141
+
142
+ #endif
@@ -0,0 +1,49 @@
1
+ /************************************************
2
+
3
+ whirlpool.c - provides Digest::Whirlpool class
4
+
5
+ $Author$
6
+
7
+ Copyright (C) 2006 Akinori MUSHA
8
+
9
+ $Id$
10
+
11
+ ************************************************/
12
+
13
+ #include "digest.h"
14
+ #include "whirlpool-algorithm.h"
15
+ #include "whirlpool-portability.h"
16
+
17
+ static void WP_Update(WP_Struct * const, const unsigned char * const, size_t);
18
+
19
+ static rb_digest_metadata_t whirlpool = {
20
+ RUBY_DIGEST_API_VERSION,
21
+ WP_DIGEST_SIZE,
22
+ WBLOCKBYTES,
23
+ sizeof(WP_Struct),
24
+ (rb_digest_hash_init_func_t)WP_Init,
25
+ (rb_digest_hash_update_func_t)WP_Update,
26
+ (rb_digest_hash_finish_func_t)WP_Finalize,
27
+ };
28
+
29
+ static void
30
+ WP_Update(WP_Struct * const wp, const unsigned char * const data, size_t len)
31
+ {
32
+ WP_Add(data, len * 8, wp);
33
+ }
34
+
35
+ void
36
+ Init_whirlpool()
37
+ {
38
+ VALUE mDigest, cDigest_Base, cDigest_Whirlpool;
39
+
40
+ rb_require("digest");
41
+
42
+ mDigest = rb_path2class("Digest");
43
+ cDigest_Base = rb_path2class("Digest::Base");
44
+
45
+ cDigest_Whirlpool = rb_define_class_under(mDigest, "Whirlpool", cDigest_Base);
46
+
47
+ rb_ivar_set(cDigest_Whirlpool, rb_intern("metadata"),
48
+ Data_Wrap_Struct(rb_cObject, 0, 0, &whirlpool));
49
+ }
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: digest-whirlpool
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Akinori MUSHA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-13 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: |
17
+ This is a Digest module implementing the Whirlpool hashing algorithm.
18
+ The size of a Whirlpool hash value is 512 bits.
19
+
20
+ email: knu@idaemons.org
21
+ executables: []
22
+
23
+ extensions:
24
+ - ext/digest/whirlpool/extconf.rb
25
+ extra_rdoc_files:
26
+ - LICENSE
27
+ - README.rdoc
28
+ files:
29
+ - ext/digest/whirlpool/depend
30
+ - ext/digest/whirlpool/extconf.rb
31
+ - ext/digest/whirlpool/whirlpool-algorithm.c
32
+ - ext/digest/whirlpool/whirlpool-algorithm.h
33
+ - ext/digest/whirlpool/whirlpool-constants.h
34
+ - ext/digest/whirlpool/whirlpool-portability.h
35
+ - ext/digest/whirlpool/whirlpool.c
36
+ - LICENSE
37
+ - README.rdoc
38
+ has_rdoc: true
39
+ homepage: http://github.com/knu/ruby-digest-extra
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --charset=UTF-8
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.3.5
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: A Digest module implementing the Whirlpool hashing algorithm
66
+ test_files: []
67
+