Skip to content

Commit 82f71f3

Browse files
committed
refactor: improve formatting and structure of data type definitions in cshake and digest modules
1 parent 6c3826e commit 82f71f3

File tree

3 files changed

+54
-43
lines changed

3 files changed

+54
-43
lines changed

ext/sha3/cshake.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ static const rb_data_type_t sha3_cshake_data_type = {
4949
},
5050
NULL,
5151
NULL,
52-
RUBY_TYPED_FREE_IMMEDIATELY};
52+
RUBY_TYPED_FREE_IMMEDIATELY,
53+
};
5354

5455
// Helper function to extract context from a Ruby object
5556
void get_cshake_context(VALUE obj, sp800_185_context_t **context) {

ext/sha3/digest.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,18 @@ static ID _shake_128_id;
7979
static ID _shake_256_id;
8080

8181
/* TypedData structure for sha3_digest_context_t */
82-
const rb_data_type_t sha3_digest_data_type = {"SHA3::Digest",
83-
{
84-
NULL,
85-
sha3_digest_free_context,
86-
sha3_digest_context_size,
87-
NULL,
88-
},
89-
NULL,
90-
NULL,
91-
RUBY_TYPED_FREE_IMMEDIATELY};
82+
const rb_data_type_t sha3_digest_data_type = {
83+
"SHA3::Digest",
84+
{
85+
NULL,
86+
sha3_digest_free_context,
87+
sha3_digest_context_size,
88+
NULL,
89+
},
90+
NULL,
91+
NULL,
92+
RUBY_TYPED_FREE_IMMEDIATELY,
93+
};
9294

9395
void Init_sha3_digest(void) {
9496
rb_require("digest");

ext/sha3/sp800_185.c

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,46 @@ static int kmac256_init_wrapper(void *state, void *params) {
2222
}
2323

2424
/*** Function table for SP800-185 algorithms ***/
25-
sp800_185_function_table_t sp800_185_functions[] = {{.algorithm = SP800_185_CSHAKE_128,
26-
.name = "CSHAKE128",
27-
.state_size = sizeof(cSHAKE_Instance),
28-
.is_keyed = false,
29-
.init = cshake128_init_wrapper,
30-
.update = (sp800_185_update_fn)cSHAKE128_Update,
31-
.final = (sp800_185_final_fn)cSHAKE128_Final,
32-
.squeeze = (sp800_185_squeeze_fn)cSHAKE128_Squeeze},
33-
{.algorithm = SP800_185_CSHAKE_256,
34-
.name = "CSHAKE256",
35-
.state_size = sizeof(cSHAKE_Instance),
36-
.is_keyed = false,
37-
.init = cshake256_init_wrapper,
38-
.update = (sp800_185_update_fn)cSHAKE256_Update,
39-
.final = (sp800_185_final_fn)cSHAKE256_Final,
40-
.squeeze = (sp800_185_squeeze_fn)cSHAKE256_Squeeze},
41-
{.algorithm = SP800_185_KMAC_128,
42-
.name = "KMAC128",
43-
.state_size = sizeof(KMAC_Instance),
44-
.is_keyed = true,
45-
.init = kmac128_init_wrapper,
46-
.update = (sp800_185_update_fn)KMAC128_Update,
47-
.final = (sp800_185_final_fn)KMAC128_Final,
48-
.squeeze = (sp800_185_squeeze_fn)KMAC128_Squeeze},
49-
{.algorithm = SP800_185_KMAC_256,
50-
.name = "KMAC256",
51-
.state_size = sizeof(KMAC_Instance),
52-
.is_keyed = true,
53-
.init = kmac256_init_wrapper,
54-
.update = (sp800_185_update_fn)KMAC256_Update,
55-
.final = (sp800_185_final_fn)KMAC256_Final,
56-
.squeeze = (sp800_185_squeeze_fn)KMAC256_Squeeze}};
25+
sp800_185_function_table_t sp800_185_functions[] = {{
26+
.algorithm = SP800_185_CSHAKE_128,
27+
.name = "CSHAKE128",
28+
.state_size = sizeof(cSHAKE_Instance),
29+
.is_keyed = false,
30+
.init = cshake128_init_wrapper,
31+
.update = (sp800_185_update_fn)cSHAKE128_Update,
32+
.final = (sp800_185_final_fn)cSHAKE128_Final,
33+
.squeeze = (sp800_185_squeeze_fn)cSHAKE128_Squeeze,
34+
},
35+
{
36+
.algorithm = SP800_185_CSHAKE_256,
37+
.name = "CSHAKE256",
38+
.state_size = sizeof(cSHAKE_Instance),
39+
.is_keyed = false,
40+
.init = cshake256_init_wrapper,
41+
.update = (sp800_185_update_fn)cSHAKE256_Update,
42+
.final = (sp800_185_final_fn)cSHAKE256_Final,
43+
.squeeze = (sp800_185_squeeze_fn)cSHAKE256_Squeeze,
44+
},
45+
{
46+
.algorithm = SP800_185_KMAC_128,
47+
.name = "KMAC128",
48+
.state_size = sizeof(KMAC_Instance),
49+
.is_keyed = true,
50+
.init = kmac128_init_wrapper,
51+
.update = (sp800_185_update_fn)KMAC128_Update,
52+
.final = (sp800_185_final_fn)KMAC128_Final,
53+
.squeeze = (sp800_185_squeeze_fn)KMAC128_Squeeze,
54+
},
55+
{
56+
.algorithm = SP800_185_KMAC_256,
57+
.name = "KMAC256",
58+
.state_size = sizeof(KMAC_Instance),
59+
.is_keyed = true,
60+
.init = kmac256_init_wrapper,
61+
.update = (sp800_185_update_fn)KMAC256_Update,
62+
.final = (sp800_185_final_fn)KMAC256_Final,
63+
.squeeze = (sp800_185_squeeze_fn)KMAC256_Squeeze,
64+
}};
5765

5866
/* Algorithm lookup functions */
5967
const sp800_185_function_table_t *sp800_185_get_algorithm(sp800_185_algorithm_t algorithm) {

0 commit comments

Comments
 (0)