9
9
#define MAX_DIGEST_SIZE 64
10
10
#define DEFAULT_DIGEST_LEN 512
11
11
12
- static int sha3_init_func ();
13
- static void sha3_update_func (hashState * ctx , unsigned char * str , size_t len );
14
- static int sha3_finish_func (hashState * ctx , unsigned char * digest );
12
+ static int keccak_init_func ();
13
+ static void keccak_update_func (hashState * ctx , unsigned char * str , size_t len );
14
+ static int keccak_finish_func (hashState * ctx , unsigned char * digest );
15
15
16
16
/*
17
- Metadata definition for the SHA3 algorithm.
17
+ Metadata definition for the Keccak algorithm.
18
18
Defines the Version, sizes for block and digest as well as
19
19
the entry points for the algorithms
20
20
*/
21
- static rb_digest_metadata_t sha3 = {
21
+ static rb_digest_metadata_t keccak = {
22
22
RUBY_DIGEST_API_VERSION ,
23
23
DEFAULT_DIGEST_LEN ,
24
24
KeccakPermutationSize - (2 * DEFAULT_DIGEST_LEN ), //size of blocks
25
25
sizeof (hashState ), //size of context for the object we'll be passed in below functions.
26
- (rb_digest_hash_init_func_t )sha3_init_func ,
27
- (rb_digest_hash_update_func_t )sha3_update_func ,
28
- (rb_digest_hash_finish_func_t )sha3_finish_func ,
26
+ (rb_digest_hash_init_func_t )keccak_init_func ,
27
+ (rb_digest_hash_update_func_t )keccak_update_func ,
28
+ (rb_digest_hash_finish_func_t )keccak_finish_func ,
29
29
};
30
30
31
31
/* Initialization function for the algorithm,
32
32
gets called during allocation of the digest object.
33
33
we override initialize to do custom hash size, so we don't care too much here.
34
34
*/
35
35
static int
36
- sha3_init_func () {
36
+ keccak_init_func () {
37
37
// Just return a 1 'successful' we override the init function
38
38
// so this is not necessary
39
39
// the base class alloc calls this to initialize the algorithm
@@ -42,29 +42,29 @@ sha3_init_func() {
42
42
43
43
/* Update function, take the current context and add str to it */
44
44
static void
45
- sha3_update_func (hashState * ctx , unsigned char * str , size_t len ) {
45
+ keccak_update_func (hashState * ctx , unsigned char * str , size_t len ) {
46
46
Update (ctx , str , len * 8 );
47
47
}
48
48
49
49
/* Finish the hash calculation and return the finished string */
50
50
static int
51
- sha3_finish_func (hashState * ctx , unsigned char * digest ) {
51
+ keccak_finish_func (hashState * ctx , unsigned char * digest ) {
52
52
Final (ctx , digest );
53
53
return 1 ;
54
54
}
55
55
56
- /* Ruby method. Digest::SHA3 #finish()
56
+ /* Ruby method. Digest::Keccak #finish()
57
57
* No Arguments
58
58
* @returns [String] Encoded Digest String
59
59
*/
60
60
static VALUE
61
- rb_sha3_finish (VALUE self ) {
61
+ rb_keccak_finish (VALUE self ) {
62
62
hashState * ctx ;
63
63
VALUE digest ;
64
64
65
65
ctx = (hashState * )RTYPEDDATA_DATA (self );
66
66
digest = rb_str_new (0 , ctx -> capacity / 2 / 8 );
67
- sha3_finish_func (ctx , (unsigned char * )RSTRING_PTR (digest ));
67
+ keccak_finish_func (ctx , (unsigned char * )RSTRING_PTR (digest ));
68
68
69
69
return digest ;
70
70
}
@@ -73,7 +73,7 @@ rb_sha3_finish(VALUE self) {
73
73
* initialize the ctx with the bitlength
74
74
*/
75
75
static void
76
- sha3_init (hashState * ctx , size_t bitlen ) {
76
+ keccak_init (hashState * ctx , size_t bitlen ) {
77
77
switch (Init (ctx , bitlen )) {
78
78
case SUCCESS :
79
79
return ;
@@ -86,12 +86,12 @@ sha3_init(hashState *ctx, size_t bitlen) {
86
86
}
87
87
}
88
88
89
- /* Ruby method. Digest::SHA3 .new(hashlen)
89
+ /* Ruby method. Digest::Keccak .new(hashlen)
90
90
* @param hashlen The length of hash, only supports 224, 256, 384 or 512
91
- * @returns [Digest::SHA3 ] new object.
91
+ * @returns [Digest::Keccak ] new object.
92
92
*/
93
93
static VALUE
94
- rb_sha3_initialize (int argc , VALUE * argv , VALUE self ) {
94
+ rb_keccak_initialize (int argc , VALUE * argv , VALUE self ) {
95
95
hashState * ctx ;
96
96
VALUE hashlen ;
97
97
int i_hashlen ;
@@ -106,48 +106,48 @@ rb_sha3_initialize(int argc, VALUE *argv, VALUE self) {
106
106
}
107
107
108
108
ctx = (hashState * )RTYPEDDATA_DATA (self );
109
- sha3_init (ctx , i_hashlen );
109
+ keccak_init (ctx , i_hashlen );
110
110
111
111
return rb_call_super (0 , NULL );
112
112
}
113
113
114
- /* Ruby method. Digest::SHA3 #digest_length
114
+ /* Ruby method. Digest::Keccak #digest_length
115
115
* @returns [Numeric] Length of the digest.
116
116
*/
117
117
static VALUE
118
- rb_sha3_digest_length (VALUE self ) {
118
+ rb_keccak_digest_length (VALUE self ) {
119
119
hashState * ctx ;
120
120
121
121
ctx = (hashState * )RTYPEDDATA_DATA (self );
122
122
return INT2FIX (ctx -> capacity / 2 / 8 );
123
123
}
124
124
125
- /* Ruby method. Digest::SHA3 #block_length
125
+ /* Ruby method. Digest::Keccak #block_length
126
126
* @returns [Numeric] Length of blocks in this digest.
127
127
*/
128
128
static VALUE
129
- rb_sha3_block_length (VALUE self ) {
129
+ rb_keccak_block_length (VALUE self ) {
130
130
hashState * ctx ;
131
131
132
132
ctx = (hashState * )RTYPEDDATA_DATA (self );
133
133
return INT2FIX (ctx -> rate / 8 );
134
134
}
135
135
136
136
void __attribute__((visibility ("default" )))
137
- Init_sha3 () {
138
- VALUE mDigest , cDigest_Base , cSHA3 ;
137
+ Init_keccak () {
138
+ VALUE mDigest , cDigest_Base , cKeccak ;
139
139
140
140
rb_require ("digest" );
141
141
142
142
mDigest = rb_path2class ("Digest" );
143
143
cDigest_Base = rb_path2class ("Digest::Base" );
144
144
145
- cSHA3 = rb_define_class_under (mDigest , "SHA3 " , cDigest_Base );
145
+ cKeccak = rb_define_class_under (mDigest , "Keccak " , cDigest_Base );
146
146
147
- rb_iv_set (cSHA3 , "metadata" , Data_Wrap_Struct (0 , 0 , 0 , (void * )& sha3 ));
147
+ rb_iv_set (cKeccak , "metadata" , Data_Wrap_Struct (0 , 0 , 0 , (void * )& keccak ));
148
148
149
- rb_define_method (cSHA3 , "initialize" , rb_sha3_initialize , -1 );
150
- rb_define_method (cSHA3 , "digest_length" , rb_sha3_digest_length , 0 );
151
- rb_define_method (cSHA3 , "block_length" , rb_sha3_block_length , 0 );
152
- rb_define_method (cSHA3 , "finish" , rb_sha3_finish , 0 );
149
+ rb_define_method (cKeccak , "initialize" , rb_keccak_initialize , -1 );
150
+ rb_define_method (cKeccak , "digest_length" , rb_keccak_digest_length , 0 );
151
+ rb_define_method (cKeccak , "block_length" , rb_keccak_block_length , 0 );
152
+ rb_define_method (cKeccak , "finish" , rb_keccak_finish , 0 );
153
153
}
0 commit comments