Make 512 bits the default
This commit is contained in:
parent
b97c745e6c
commit
7644ea4fe9
1 changed files with 12 additions and 4 deletions
|
@ -11,19 +11,27 @@ typedef struct {
|
||||||
} RbSHA3;
|
} RbSHA3;
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_sha3_new(VALUE klass, VALUE bitlen) {
|
rb_sha3_new(int argc, VALUE *argv, VALUE klass) {
|
||||||
RbSHA3 *ctx;
|
RbSHA3 *ctx;
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
|
VALUE hashlen;
|
||||||
|
int i_hashlen;
|
||||||
|
|
||||||
|
if (rb_scan_args(argc, argv, "01", &hashlen) == 0) {
|
||||||
|
i_hashlen = 512;
|
||||||
|
} else {
|
||||||
|
i_hashlen = NUM2INT(hashlen);
|
||||||
|
}
|
||||||
|
|
||||||
ctx = (RbSHA3 *) xmalloc(sizeof(RbSHA3));
|
ctx = (RbSHA3 *) xmalloc(sizeof(RbSHA3));
|
||||||
obj = Data_Wrap_Struct(klass, 0, xfree, ctx);
|
obj = Data_Wrap_Struct(klass, 0, xfree, ctx);
|
||||||
ctx->bitlen = NUM2INT(bitlen);
|
ctx->bitlen = i_hashlen;
|
||||||
|
|
||||||
if (ctx->bitlen == 0) {
|
if (ctx->bitlen == 0) {
|
||||||
rb_raise(rb_eRuntimeError, "Unsupported hash length");
|
rb_raise(rb_eRuntimeError, "Unsupported hash length");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (Init(&ctx->state, ctx->bitlen)) {
|
switch (Init(&ctx->state, i_hashlen)) {
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
return obj;
|
return obj;
|
||||||
case FAIL:
|
case FAIL:
|
||||||
|
@ -115,7 +123,7 @@ void
|
||||||
Init_sha3() {
|
Init_sha3() {
|
||||||
mDigest = rb_define_module("Digest");
|
mDigest = rb_define_module("Digest");
|
||||||
cSHA3 = rb_define_class_under(mDigest, "SHA3", rb_cObject);
|
cSHA3 = rb_define_class_under(mDigest, "SHA3", rb_cObject);
|
||||||
rb_define_singleton_method(cSHA3, "new", rb_sha3_new, 1);
|
rb_define_singleton_method(cSHA3, "new", rb_sha3_new, -1);
|
||||||
rb_define_method(cSHA3, "initialize_copy", rb_sha3_copy, 1);
|
rb_define_method(cSHA3, "initialize_copy", rb_sha3_copy, 1);
|
||||||
rb_define_method(cSHA3, "reset", rb_sha3_reset, 0);
|
rb_define_method(cSHA3, "reset", rb_sha3_reset, 0);
|
||||||
rb_define_method(cSHA3, "update", rb_sha3_update, 1);
|
rb_define_method(cSHA3, "update", rb_sha3_update, 1);
|
||||||
|
|
Loading…
Reference in a new issue