sha3 2.2.2 → 2.2.4
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -0
- data/.rubocop.yml +66 -0
- data/CHANGELOG.md +34 -0
- data/README.md +1 -0
- data/certs/io+sha3@jsg.io.pem +20 -20
- data/ext/sha3/common.h +118 -0
- data/ext/sha3/cshake.c +18 -95
- data/ext/sha3/digest.c +106 -79
- data/ext/sha3/kmac.c +18 -97
- data/ext/sha3/sp800_185.c +87 -47
- data/lib/constants.rb +1 -1
- data/sha3.gemspec +5 -5
- data.tar.gz.sig +0 -0
- metadata +24 -23
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 313cf6f3d1b2847839a7ced1c6c80a8f979d02bbb63be4d6aad29d8aa867e94f
|
|
4
|
+
data.tar.gz: 8082b5d96c084bd05e86d7213ed17b982200381dd7f187ffa1bfd122e44ceeac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3c1fce17c84d6c28cd1d2695b0aee6c6ef122ad76e16558ba8788f1ea952f626448af264541e8161f3e4835da292b76da7f46dd4e21061ecce8cadf77ba93791
|
|
7
|
+
data.tar.gz: deb57b637c2e3c7ec65b189de11404005e72e3809e1b3cbc982a3ce66ba2918d597e7a5039e373200afb1ce0d23ccf704d7d2974f9799b229b74486eb009b7b0
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/.document
CHANGED
data/.rubocop.yml
CHANGED
|
@@ -6,8 +6,74 @@ AllCops:
|
|
|
6
6
|
NewCops: enable
|
|
7
7
|
TargetRubyVersion: 2.7
|
|
8
8
|
|
|
9
|
+
Exclude:
|
|
10
|
+
- ext/**/*.rb
|
|
11
|
+
|
|
9
12
|
Layout/LineLength:
|
|
10
13
|
Max: 120
|
|
11
14
|
|
|
15
|
+
# Metrics
|
|
16
|
+
|
|
17
|
+
Metrics/AbcSize:
|
|
18
|
+
Exclude:
|
|
19
|
+
- spec/**/*_spec.rb
|
|
20
|
+
|
|
21
|
+
Metrics/CyclomaticComplexity:
|
|
22
|
+
Exclude:
|
|
23
|
+
- spec/**/*_spec.rb
|
|
24
|
+
|
|
25
|
+
Metrics/PerceivedComplexity:
|
|
26
|
+
Exclude:
|
|
27
|
+
- spec/**/*_spec.rb
|
|
28
|
+
|
|
29
|
+
Metrics/MethodLength:
|
|
30
|
+
Max: 15
|
|
31
|
+
Exclude:
|
|
32
|
+
- spec/**/*_spec.rb
|
|
33
|
+
|
|
34
|
+
# Naming
|
|
35
|
+
|
|
36
|
+
Naming/ClassAndModuleCamelCase:
|
|
37
|
+
Enabled: false
|
|
38
|
+
|
|
12
39
|
Naming/VariableNumber:
|
|
13
40
|
EnforcedStyle: snake_case
|
|
41
|
+
Exclude:
|
|
42
|
+
- spec/**/*.rb
|
|
43
|
+
|
|
44
|
+
# Security
|
|
45
|
+
|
|
46
|
+
# Allow URI.open for test vector downloads
|
|
47
|
+
Security/Open:
|
|
48
|
+
Exclude:
|
|
49
|
+
- spec/sha3_digest_vectors_spec.rb
|
|
50
|
+
|
|
51
|
+
# RSpec configuration
|
|
52
|
+
|
|
53
|
+
RSpec/ExampleLength:
|
|
54
|
+
Max: 15
|
|
55
|
+
CountAsOne:
|
|
56
|
+
- array
|
|
57
|
+
- hash
|
|
58
|
+
- heredoc
|
|
59
|
+
|
|
60
|
+
RSpec/MultipleExpectations:
|
|
61
|
+
Max: 8
|
|
62
|
+
|
|
63
|
+
RSpec/SpecFilePathFormat:
|
|
64
|
+
Enabled: false
|
|
65
|
+
|
|
66
|
+
RSpec/LeakyConstantDeclaration:
|
|
67
|
+
Enabled: false
|
|
68
|
+
|
|
69
|
+
RSpec/BeforeAfterAll:
|
|
70
|
+
Enabled: false
|
|
71
|
+
|
|
72
|
+
RSpec/MultipleDescribes:
|
|
73
|
+
Enabled: false
|
|
74
|
+
|
|
75
|
+
RSpec/NamedSubject:
|
|
76
|
+
Enabled: false
|
|
77
|
+
|
|
78
|
+
RSpec/DescribeClass:
|
|
79
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# SHA3 Ruby Gem Changelog
|
|
2
2
|
|
|
3
|
+
## v2.2.3 (2025-09-05)
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
- Fixed memory leak by freeing context memory on allocation failure in rb_sha3_digest_alloc
|
|
7
|
+
- Fixed heredoc delimiters for description and post-install message in gemspec
|
|
8
|
+
- Fixed example comment typo in cshake
|
|
9
|
+
|
|
10
|
+
### Improvements
|
|
11
|
+
- Introduced common abstraction layer for SP800-185 algorithms (cSHAKE, KMAC)
|
|
12
|
+
- Improved memory management and error handling in digest.c
|
|
13
|
+
- Significantly reduced code duplication in cshake.c and kmac.c
|
|
14
|
+
|
|
15
|
+
### Testing
|
|
16
|
+
- Improved test organization and coverage for SHA3 algorithms
|
|
17
|
+
- Added comprehensive tests for edge cases and error conditions
|
|
18
|
+
|
|
19
|
+
### Maintenance
|
|
20
|
+
- Added RuboCop configuration for code style consistency
|
|
21
|
+
|
|
22
|
+
## v2.2.2 (2025-09-05)
|
|
23
|
+
|
|
24
|
+
### Improvements
|
|
25
|
+
- Streamlined SP800-185 algorithm initialization
|
|
26
|
+
- Enhanced error handling in cSHAKE and KMAC implementations
|
|
27
|
+
- Refactored internal API for better maintainability
|
|
28
|
+
|
|
29
|
+
## v2.2.1 (2025-09-05)
|
|
30
|
+
|
|
31
|
+
### Bug Fixes
|
|
32
|
+
- Fixed out-of-bounds array access when parsing optional key arguments in cSHAKE
|
|
33
|
+
|
|
34
|
+
### Maintenance
|
|
35
|
+
- Removed obsolete macro definitions for Ruby methods in SP800-185 header
|
|
36
|
+
|
|
3
37
|
## v2.2.0 (2025-03-15)
|
|
4
38
|
|
|
5
39
|
### Features
|
data/README.md
CHANGED
|
@@ -38,6 +38,7 @@ This gem provides support for the standard SHA-3 fixed-length functions (224, 25
|
|
|
38
38
|
- [API Documentation](https://docs.jsg.io/sha3/html/index.html)
|
|
39
39
|
- [GitHub Repository](https://github.com/johanns/sha3#readme)
|
|
40
40
|
- [Issue Tracker](https://github.com/johanns/sha3/issues)
|
|
41
|
+
- [Changelog](CHANGELOG.md)
|
|
41
42
|
|
|
42
43
|
## Features
|
|
43
44
|
|
data/certs/io+sha3@jsg.io.pem
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
-----BEGIN CERTIFICATE-----
|
|
2
2
|
MIIEYDCCAsigAwIBAgIBATANBgkqhkiG9w0BAQsFADA7MRAwDgYDVQQDDAdpb19z
|
|
3
3
|
aGEzMRMwEQYKCZImiZPyLGQBGRYDanNnMRIwEAYKCZImiZPyLGQBGRYCaW8wHhcN
|
|
4
|
-
|
|
4
|
+
MjYwNTE3MjAwNTE1WhcNMjgwNTE2MjAwNTE1WjA7MRAwDgYDVQQDDAdpb19zaGEz
|
|
5
5
|
MRMwEQYKCZImiZPyLGQBGRYDanNnMRIwEAYKCZImiZPyLGQBGRYCaW8wggGiMA0G
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC16QqqWL49C7rqtj8HoYMippjH6T4A
|
|
7
|
+
MvK8w1nXPsGOhIP0BYcjNajdFxzOXZ9NcYPxosQAvY97THO7zEGsM2VrvPzsPL8J
|
|
8
|
+
8DqRS6wHUezA2ZffGpUvsesNlIpzSkEXXXRTe/8dq2/TnIeKEyx4dhu1cKL6h/22
|
|
9
|
+
Mng14M25QJK0JI5xhQ/+i9UXeNCwFjwINbOzJD1XZ2VtOJkMm/yHZvB6ww8qu+gS
|
|
10
|
+
N4J2iiCbFRsbYRPuoVFVuSOD0lgX1tvwOtUucSdF1EzvEX5XW2avzOWsKab0V3ET
|
|
11
|
+
puZ9F36dmkfNan5n5GApyKkOZ/mfC8s9brjRXVlp4YPHBK3zFEU6VsCtIa08dPXI
|
|
12
|
+
axUZlmwQLhvtsnX3nkgvbGpvFZmhBs4JBssEur7Gf9bgLbXYngfmgIZv5WFRravJ
|
|
13
|
+
qvHCehkpVgqi+ebW15UzhPwQ5wNxdm/I+tAt/u08m0R4m6kQYbk2yAimjrVLx0f/
|
|
14
|
+
JPcoi+4QXrmYZujkhqhIw2lDPOCD2oKPUVECAwEAAaNvMG0wCQYDVR0TBAIwADAL
|
|
15
|
+
BgNVHQ8EBAMCBLAwHQYDVR0OBBYEFKuRt91muWm/9XZBRDt8Nkm1IdjdMBkGA1Ud
|
|
16
16
|
EQQSMBCBDmlvK3NoYTNAanNnLmlvMBkGA1UdEgQSMBCBDmlvK3NoYTNAanNnLmlv
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
+
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
MA0GCSqGSIb3DQEBCwUAA4IBgQBI38LgcqdqpfkaiEGfr3fLtsOBkE1Q7mEHjeIS
|
|
18
|
+
JcEiu16sP0iR/0QzN/DS0vPMQUhl4dvkUl7euVOo8rp0mwzUyaSvq+MSQlpxwgjb
|
|
19
|
+
AQ5A8VAkkIMbTbCqRU9q9KQObmO8/NaFFFGgmRegp8eBEGdixbiIsReEeWzEICe1
|
|
20
|
+
TOmXWl1X7EBUF7CdSIHxBAjF16YXJoDJp16DonZ/pzbgeO85OzFmfnA+B9nsHXS4
|
|
21
|
+
3CeJ/lKznIM8XWSXA1ruSkZeB5ouNtauqSAaBJoMkAB0DbOrZ6yo/mP8x3WtSLKY
|
|
22
|
+
SdQdy412nPewWa08VXIjZqd1Q+rI9Wq2pY6TOqML1Iu5nB2VMAr9PoHcIPz1P9N8
|
|
23
|
+
sM8XX4fXOsMtSc4SzMOqlkg2qRdo4/1eIjVSxCM84VqppRnH8syAzny6COQ0Xo+z
|
|
24
|
+
/PqqO8TUsynEGVsjIkBIa8Y5zoXBfcQ6PQpSbeY0bXhhsxclL3fKWSQQC4MN/OFE
|
|
25
|
+
5aeBE+xHYdmI3UoIAXt1xB0hU9w=
|
|
26
26
|
-----END CERTIFICATE-----
|
data/ext/sha3/common.h
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Copyright (c) 2025 Johanns Gregorian <io+sha3@jsg.io>
|
|
2
|
+
|
|
3
|
+
#ifndef _SHA3_COMMON_H_
|
|
4
|
+
#define _SHA3_COMMON_H_
|
|
5
|
+
|
|
6
|
+
#include <ruby.h>
|
|
7
|
+
|
|
8
|
+
#include "sp800_185.h"
|
|
9
|
+
|
|
10
|
+
#ifdef __cplusplus
|
|
11
|
+
extern "C" {
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
/* Common macros for SP800-185 based implementations (CSHAKE, KMAC) */
|
|
15
|
+
|
|
16
|
+
/* Define a simple method that just calls an sp800_185 function */
|
|
17
|
+
#define DEFINE_SP800_185_SIMPLE_METHOD(method_name, sp_func, get_ctx_func) \
|
|
18
|
+
static VALUE method_name(VALUE self, VALUE data) { \
|
|
19
|
+
sp800_185_context_t *context; \
|
|
20
|
+
get_ctx_func(self, &context); \
|
|
21
|
+
sp_func(context, data); \
|
|
22
|
+
return self; \
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* Define a method that returns a value from sp800_185 function */
|
|
26
|
+
#define DEFINE_SP800_185_RETURN_METHOD(method_name, sp_func, get_ctx_func) \
|
|
27
|
+
static VALUE method_name(VALUE self) { \
|
|
28
|
+
sp800_185_context_t *context; \
|
|
29
|
+
get_ctx_func(self, &context); \
|
|
30
|
+
return sp_func(context); \
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* Define a method with single VALUE parameter that returns VALUE */
|
|
34
|
+
#define DEFINE_SP800_185_VALUE_METHOD(method_name, sp_func, get_ctx_func) \
|
|
35
|
+
static VALUE method_name(VALUE self, VALUE param) { \
|
|
36
|
+
sp800_185_context_t *context; \
|
|
37
|
+
get_ctx_func(self, &context); \
|
|
38
|
+
return sp_func(context, param); \
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* Define a method with variable arguments */
|
|
42
|
+
#define DEFINE_SP800_185_VARARGS_METHOD(method_name, sp_func, get_ctx_func) \
|
|
43
|
+
static VALUE method_name(int argc, VALUE *argv, VALUE self) { \
|
|
44
|
+
sp800_185_context_t *context; \
|
|
45
|
+
get_ctx_func(self, &context); \
|
|
46
|
+
VALUE param = argc > 0 ? argv[0] : Qnil; \
|
|
47
|
+
return sp_func(context, param); \
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* Define common memory management functions */
|
|
51
|
+
#define DEFINE_SP800_185_MEMORY_FUNCS(prefix, context_type) \
|
|
52
|
+
static void prefix##_free_context(void *ptr) { sp800_185_free_context((sp800_185_context_t *)ptr); } \
|
|
53
|
+
\
|
|
54
|
+
static size_t prefix##_context_size(const void *ptr) { \
|
|
55
|
+
return sp800_185_context_size((const sp800_185_context_t *)ptr, sizeof(context_type)); \
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* Define common allocation function */
|
|
59
|
+
#define DEFINE_SP800_185_ALLOC(prefix, context_type, instance_type, error_class) \
|
|
60
|
+
static VALUE rb_##prefix##_alloc(VALUE klass) { \
|
|
61
|
+
context_type *context = (context_type *)sp800_185_alloc_context(sizeof(context_type), sizeof(instance_type)); \
|
|
62
|
+
\
|
|
63
|
+
if (!context) { \
|
|
64
|
+
rb_raise(error_class, "failed to allocate memory"); \
|
|
65
|
+
} \
|
|
66
|
+
\
|
|
67
|
+
VALUE obj = TypedData_Wrap_Struct(klass, &prefix##_data_type, context); \
|
|
68
|
+
return obj; \
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/* Define common copy method */
|
|
72
|
+
#define DEFINE_SP800_185_COPY_METHOD(method_name, context_type, data_type, class_var) \
|
|
73
|
+
static VALUE method_name(VALUE self, VALUE other) { \
|
|
74
|
+
context_type *context, *other_context; \
|
|
75
|
+
\
|
|
76
|
+
rb_check_frozen(self); \
|
|
77
|
+
if (self == other) { \
|
|
78
|
+
return self; \
|
|
79
|
+
} \
|
|
80
|
+
\
|
|
81
|
+
if (!rb_obj_is_kind_of(other, class_var)) { \
|
|
82
|
+
rb_raise(rb_eTypeError, "wrong argument (%s)! (expected %s)", rb_obj_classname(other), \
|
|
83
|
+
rb_class2name(class_var)); \
|
|
84
|
+
} \
|
|
85
|
+
\
|
|
86
|
+
TypedData_Get_Struct(other, context_type, &data_type, other_context); \
|
|
87
|
+
TypedData_Get_Struct(self, context_type, &data_type, context); \
|
|
88
|
+
\
|
|
89
|
+
/* Copy the base context attributes */ \
|
|
90
|
+
context->base.functions = other_context->base.functions; \
|
|
91
|
+
context->base.output_length = other_context->base.output_length; \
|
|
92
|
+
context->base.error_class = other_context->base.error_class; \
|
|
93
|
+
\
|
|
94
|
+
/* Copy the algorithm-specific state */ \
|
|
95
|
+
if (context->base.functions && other_context->base.state) { \
|
|
96
|
+
memcpy(context->base.state, other_context->base.state, context->base.functions->state_size); \
|
|
97
|
+
} \
|
|
98
|
+
\
|
|
99
|
+
return self; \
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* Ruby wrapper functions for SP800-185 operations */
|
|
103
|
+
VALUE sp800_185_rb_update(sp800_185_context_t *context, VALUE data);
|
|
104
|
+
VALUE sp800_185_rb_name(sp800_185_context_t *context);
|
|
105
|
+
VALUE sp800_185_rb_finish(sp800_185_context_t *context, VALUE output);
|
|
106
|
+
VALUE sp800_185_rb_digest(sp800_185_context_t *context, VALUE data);
|
|
107
|
+
VALUE sp800_185_rb_hexdigest(sp800_185_context_t *context, VALUE data);
|
|
108
|
+
VALUE sp800_185_rb_squeeze(sp800_185_context_t *context, VALUE length);
|
|
109
|
+
VALUE sp800_185_rb_hex_squeeze(sp800_185_context_t *context, VALUE length);
|
|
110
|
+
|
|
111
|
+
/* Helper function to register common methods */
|
|
112
|
+
void register_sp800_185_common_methods(VALUE klass);
|
|
113
|
+
|
|
114
|
+
#ifdef __cplusplus
|
|
115
|
+
}
|
|
116
|
+
#endif
|
|
117
|
+
|
|
118
|
+
#endif /* _SHA3_COMMON_H_ */
|
data/ext/sha3/cshake.c
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#include "cshake.h"
|
|
2
2
|
|
|
3
|
+
#include "common.h"
|
|
3
4
|
#include "sha3.h"
|
|
4
5
|
#include "sp800_185.h"
|
|
5
6
|
|
|
@@ -48,7 +49,8 @@ static const rb_data_type_t sha3_cshake_data_type = {
|
|
|
48
49
|
},
|
|
49
50
|
NULL,
|
|
50
51
|
NULL,
|
|
51
|
-
RUBY_TYPED_FREE_IMMEDIATELY
|
|
52
|
+
RUBY_TYPED_FREE_IMMEDIATELY,
|
|
53
|
+
};
|
|
52
54
|
|
|
53
55
|
// Helper function to extract context from a Ruby object
|
|
54
56
|
void get_cshake_context(VALUE obj, sp800_185_context_t **context) {
|
|
@@ -76,7 +78,7 @@ void Init_sha3_cshake(void) {
|
|
|
76
78
|
/*
|
|
77
79
|
* Document-class: SHA3::CSHAKE::Error
|
|
78
80
|
*
|
|
79
|
-
* All
|
|
81
|
+
* All CSHAKE methods raise this exception on error.
|
|
80
82
|
*
|
|
81
83
|
* It is a subclass of the StandardError class -- see the Ruby documentation
|
|
82
84
|
* for more information.
|
|
@@ -104,25 +106,11 @@ void Init_sha3_cshake(void) {
|
|
|
104
106
|
return;
|
|
105
107
|
}
|
|
106
108
|
|
|
107
|
-
|
|
109
|
+
/* Use common memory management functions */
|
|
110
|
+
DEFINE_SP800_185_MEMORY_FUNCS(sha3_cshake, sha3_cshake_context_t)
|
|
108
111
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
static VALUE rb_sha3_cshake_alloc(VALUE klass) {
|
|
114
|
-
sha3_cshake_context_t *context =
|
|
115
|
-
(sha3_cshake_context_t *)sp800_185_alloc_context(sizeof(sha3_cshake_context_t), sizeof(cSHAKE_Instance));
|
|
116
|
-
|
|
117
|
-
if (!context) {
|
|
118
|
-
rb_raise(_sha3_cshake_error_class, "failed to allocate memory");
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Create the Ruby object with TypedData - this will automatically handle freeing
|
|
122
|
-
VALUE obj = TypedData_Wrap_Struct(klass, &sha3_cshake_data_type, context);
|
|
123
|
-
|
|
124
|
-
return obj;
|
|
125
|
-
}
|
|
112
|
+
/* Use common allocation function */
|
|
113
|
+
DEFINE_SP800_185_ALLOC(sha3_cshake, sha3_cshake_context_t, cSHAKE_Instance, _sha3_cshake_error_class)
|
|
126
114
|
|
|
127
115
|
/*
|
|
128
116
|
* :call-seq:
|
|
@@ -144,14 +132,14 @@ static VALUE rb_sha3_cshake_alloc(VALUE klass) {
|
|
|
144
132
|
* _optional_ The customization string to use
|
|
145
133
|
*
|
|
146
134
|
* = example
|
|
147
|
-
* # Initialize instance for
|
|
135
|
+
* # Initialize instance for fixed-length operation
|
|
148
136
|
* cshake = SHA3::CSHAKE.new(:cshake_128, 32, name: 'my-app')
|
|
149
137
|
* cshake << 'data...'
|
|
150
138
|
* cshake.hexdigest
|
|
151
139
|
*
|
|
152
140
|
* # Initialize instance for XOF operation (arbitrary-long output)
|
|
153
141
|
* cshake = SHA3::CSHAKE.new(:cshake_256, 0, customization: 'Email Signature')
|
|
154
|
-
*
|
|
142
|
+
* cshake.update('data...')
|
|
155
143
|
* cshake.squeeze(64)
|
|
156
144
|
*/
|
|
157
145
|
static VALUE rb_sha3_cshake_init(int argc, VALUE *argv, VALUE self) {
|
|
@@ -233,31 +221,7 @@ static VALUE rb_sha3_cshake_init(int argc, VALUE *argv, VALUE self) {
|
|
|
233
221
|
* = example
|
|
234
222
|
* cshake2 = cshake.dup
|
|
235
223
|
*/
|
|
236
|
-
|
|
237
|
-
sha3_cshake_context_t *context, *other_context;
|
|
238
|
-
|
|
239
|
-
rb_check_frozen(self);
|
|
240
|
-
if (self == other) {
|
|
241
|
-
return self;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (!rb_obj_is_kind_of(other, _sha3_cshake_class)) {
|
|
245
|
-
rb_raise(rb_eTypeError, "wrong argument (%s)! (expected %s)", rb_obj_classname(other),
|
|
246
|
-
rb_class2name(_sha3_cshake_class));
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
TypedData_Get_Struct(other, sha3_cshake_context_t, &sha3_cshake_data_type, other_context);
|
|
250
|
-
TypedData_Get_Struct(self, sha3_cshake_context_t, &sha3_cshake_data_type, context);
|
|
251
|
-
|
|
252
|
-
// Copy the base context attributes
|
|
253
|
-
context->base.functions = other_context->base.functions;
|
|
254
|
-
context->base.output_length = other_context->base.output_length;
|
|
255
|
-
|
|
256
|
-
// Copy the algorithm-specific state
|
|
257
|
-
memcpy(context->base.state, other_context->base.state, context->base.functions->state_size);
|
|
258
|
-
|
|
259
|
-
return self;
|
|
260
|
-
}
|
|
224
|
+
DEFINE_SP800_185_COPY_METHOD(rb_sha3_cshake_copy, sha3_cshake_context_t, sha3_cshake_data_type, _sha3_cshake_class)
|
|
261
225
|
|
|
262
226
|
/*
|
|
263
227
|
* :call-seq:
|
|
@@ -272,13 +236,7 @@ static VALUE rb_sha3_cshake_copy(VALUE self, VALUE other) {
|
|
|
272
236
|
* cshake.update("more data")
|
|
273
237
|
* cshake << "more data" # alias for update
|
|
274
238
|
*/
|
|
275
|
-
|
|
276
|
-
sp800_185_context_t *context;
|
|
277
|
-
get_cshake_context(self, &context);
|
|
278
|
-
sp800_185_update(context, data);
|
|
279
|
-
|
|
280
|
-
return self;
|
|
281
|
-
}
|
|
239
|
+
DEFINE_SP800_185_SIMPLE_METHOD(rb_sha3_cshake_update, sp800_185_rb_update, get_cshake_context)
|
|
282
240
|
|
|
283
241
|
/*
|
|
284
242
|
* :call-seq:
|
|
@@ -286,12 +244,7 @@ static VALUE rb_sha3_cshake_update(VALUE self, VALUE data) {
|
|
|
286
244
|
*
|
|
287
245
|
* Returns the name of the CSHAKE instance.
|
|
288
246
|
*/
|
|
289
|
-
|
|
290
|
-
sp800_185_context_t *context;
|
|
291
|
-
get_cshake_context(self, &context);
|
|
292
|
-
|
|
293
|
-
return rb_str_new2(sp800_185_name(context));
|
|
294
|
-
}
|
|
247
|
+
DEFINE_SP800_185_RETURN_METHOD(rb_sha3_cshake_name, sp800_185_rb_name, get_cshake_context)
|
|
295
248
|
|
|
296
249
|
/*
|
|
297
250
|
* :call-seq:
|
|
@@ -305,13 +258,7 @@ static VALUE rb_sha3_cshake_name(VALUE self) {
|
|
|
305
258
|
* = example
|
|
306
259
|
* cshake.finish
|
|
307
260
|
*/
|
|
308
|
-
|
|
309
|
-
sp800_185_context_t *context;
|
|
310
|
-
get_cshake_context(self, &context);
|
|
311
|
-
|
|
312
|
-
VALUE output = argc > 0 ? argv[0] : Qnil;
|
|
313
|
-
return sp800_185_finish(context, output);
|
|
314
|
-
}
|
|
261
|
+
DEFINE_SP800_185_VARARGS_METHOD(rb_sha3_cshake_finish, sp800_185_rb_finish, get_cshake_context)
|
|
315
262
|
|
|
316
263
|
/*
|
|
317
264
|
* :call-seq:
|
|
@@ -326,14 +273,7 @@ static VALUE rb_sha3_cshake_finish(int argc, VALUE *argv, VALUE self) {
|
|
|
326
273
|
* cshake.digest
|
|
327
274
|
* cshake.digest("final chunk")
|
|
328
275
|
*/
|
|
329
|
-
|
|
330
|
-
sp800_185_context_t *context;
|
|
331
|
-
get_cshake_context(self, &context);
|
|
332
|
-
|
|
333
|
-
VALUE data = argc > 0 ? argv[0] : Qnil;
|
|
334
|
-
|
|
335
|
-
return sp800_185_digest(context, data);
|
|
336
|
-
}
|
|
276
|
+
DEFINE_SP800_185_VARARGS_METHOD(rb_sha3_cshake_digest, sp800_185_rb_digest, get_cshake_context)
|
|
337
277
|
|
|
338
278
|
/*
|
|
339
279
|
* :call-seq:
|
|
@@ -348,14 +288,7 @@ static VALUE rb_sha3_cshake_digest(int argc, VALUE *argv, VALUE self) {
|
|
|
348
288
|
* cshake.hexdigest
|
|
349
289
|
* cshake.hexdigest("final chunk")
|
|
350
290
|
*/
|
|
351
|
-
|
|
352
|
-
sp800_185_context_t *context;
|
|
353
|
-
get_cshake_context(self, &context);
|
|
354
|
-
|
|
355
|
-
VALUE data = argc > 0 ? argv[0] : Qnil;
|
|
356
|
-
|
|
357
|
-
return sp800_185_hexdigest(context, data);
|
|
358
|
-
}
|
|
291
|
+
DEFINE_SP800_185_VARARGS_METHOD(rb_sha3_cshake_hexdigest, sp800_185_rb_hexdigest, get_cshake_context)
|
|
359
292
|
|
|
360
293
|
/*
|
|
361
294
|
* :call-seq:
|
|
@@ -369,12 +302,7 @@ static VALUE rb_sha3_cshake_hexdigest(int argc, VALUE *argv, VALUE self) {
|
|
|
369
302
|
* = example
|
|
370
303
|
* cshake.squeeze(32)
|
|
371
304
|
*/
|
|
372
|
-
|
|
373
|
-
sp800_185_context_t *context;
|
|
374
|
-
get_cshake_context(self, &context);
|
|
375
|
-
|
|
376
|
-
return sp800_185_squeeze(context, length);
|
|
377
|
-
}
|
|
305
|
+
DEFINE_SP800_185_VALUE_METHOD(rb_sha3_cshake_squeeze, sp800_185_rb_squeeze, get_cshake_context)
|
|
378
306
|
|
|
379
307
|
/*
|
|
380
308
|
* :call-seq:
|
|
@@ -388,9 +316,4 @@ static VALUE rb_sha3_cshake_squeeze(VALUE self, VALUE length) {
|
|
|
388
316
|
* = example
|
|
389
317
|
* cshake.hex_squeeze(32)
|
|
390
318
|
*/
|
|
391
|
-
|
|
392
|
-
sp800_185_context_t *context;
|
|
393
|
-
get_cshake_context(self, &context);
|
|
394
|
-
|
|
395
|
-
return sp800_185_hex_squeeze(context, length);
|
|
396
|
-
}
|
|
319
|
+
DEFINE_SP800_185_VALUE_METHOD(rb_sha3_cshake_hex_squeeze, sp800_185_rb_hex_squeeze, get_cshake_context)
|