10#if !defined(OPENSSL_NO_HMAC)
14#define NewHMAC(klass) \
15 TypedData_Wrap_Struct((klass), &ossl_hmac_type, 0)
16#define GetHMAC(obj, ctx) do { \
17 TypedData_Get_Struct((obj), HMAC_CTX, &ossl_hmac_type, (ctx)); \
19 ossl_raise(rb_eRuntimeError, "HMAC wasn't initialized"); \
37ossl_hmac_free(
void *ctx)
51ossl_hmac_alloc(
VALUE klass)
111 HMAC_CTX *ctx1, *ctx2;
114 if (self == other)
return self;
119 if (!HMAC_CTX_copy(ctx1, ctx2))
155hmac_final(HMAC_CTX *ctx,
unsigned char *
buf,
unsigned int *buf_len)
163 if (!HMAC_CTX_copy(
final, ctx)) {
168 HMAC_Final(
final,
buf, buf_len);
185ossl_hmac_digest(
VALUE self)
188 unsigned int buf_len;
193 hmac_final(ctx, (
unsigned char *)
RSTRING_PTR(ret), &buf_len);
194 assert(buf_len <= EVP_MAX_MD_SIZE);
208ossl_hmac_hexdigest(
VALUE self)
211 unsigned char buf[EVP_MAX_MD_SIZE];
212 unsigned int buf_len;
216 hmac_final(ctx,
buf, &buf_len);
243ossl_hmac_reset(
VALUE self)
274 unsigned int buf_len;
305 unsigned char buf[EVP_MAX_MD_SIZE];
306 unsigned int buf_len;
383# warning >>> OpenSSL is compiled without HMAC support <<<
387 rb_warning(
"HMAC is not available: OpenSSL is compiled without HMAC.");
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
#define RSTRING_LEN(string)
#define RSTRING_PTR(string)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_define_module(const char *name)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
void rb_warning(const char *fmt,...)
VALUE rb_cObject
Object class.
#define rb_str_new(str, len)
void rb_str_set_len(VALUE, long)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
void ossl_bin2hex(unsigned char *in, char *out, size_t inlen)
void ossl_raise(VALUE exc, const char *fmt,...)
const EVP_MD * ossl_evp_get_digestbyname(VALUE obj)
void Init_ossl_hmac(void)
#define GetHMAC(obj, ctx)
#define RTYPEDDATA_DATA(v)
@ RUBY_TYPED_FREE_IMMEDIATELY