Class: Digest::Keccak

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

Constant Summary collapse

VERSION =
"1.3.3"

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object

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

Parameters:

  • hashlen

    The length of hash, only supports 224, 256, 384 or 512



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

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



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

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



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

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



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

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;
}