Class: Digest::Keccak

Inherits:
Digest_Base
  • Object
show all
Defined in:
lib/digest/keccak/version.rb,
ext/digest/keccak.c

Constant Summary collapse

VERSION =
'0.0.6'

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object

Ruby method. Digest::Keccak.new(hashlen)



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'ext/digest/keccak.c', line 93

static VALUE
rb_keccak_initialize(int argc, VALUE *argv, VALUE self) {
	hashState *ctx;
	VALUE hashlen;
	int i_hashlen;

	if (rb_scan_args(argc, argv, "01", &hashlen) == 0) {
		i_hashlen = DEFAULT_DIGEST_LEN;
	} else {
		i_hashlen = NUM2INT(hashlen);
	}
	if ( i_hashlen == 0) {
		rb_raise(rb_eArgError, "Unsupported hash length");
  }

  ctx = (hashState *)RTYPEDDATA_DATA(self);
	keccak_init(ctx, i_hashlen);

	return rb_call_super(0, NULL);
}

Instance Method Details

#block_lengthObject

Ruby method. Digest::Keccak#block_length



128
129
130
131
132
133
134
# File 'ext/digest/keccak.c', line 128

static VALUE
rb_keccak_block_length(VALUE self) {
	hashState *ctx;

	ctx = (hashState *)RTYPEDDATA_DATA(self);
	return INT2FIX(ctx->rate / 8);
}

#digest_lengthObject

Ruby method. Digest::Keccak#digest_length



117
118
119
120
121
122
123
# File 'ext/digest/keccak.c', line 117

static VALUE
rb_keccak_digest_length(VALUE self) {
	hashState *ctx;

	ctx = (hashState *)RTYPEDDATA_DATA(self);
	return INT2FIX(ctx->capacity / 2 / 8);
}

#finishObject

Ruby method. Digest::Keccak#finish() No Arguments



60
61
62
63
64
65
66
67
68
69
70
# File 'ext/digest/keccak.c', line 60

static VALUE
rb_keccak_finish(VALUE self) {
  hashState *ctx;
  VALUE digest;

  ctx = (hashState *)RTYPEDDATA_DATA(self);
  digest = rb_str_new(0, ctx->capacity / 2 / 8);
  keccak_finish_func(ctx, (unsigned char *)RSTRING_PTR(digest));

  return digest;
}