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"); \ 37 ossl_hmac_free(
void *ctx)
51 ossl_hmac_alloc(
VALUE klass)
117 HMAC_CTX *ctx1, *ctx2;
120 if (
self == other)
return self;
125 if (!HMAC_CTX_copy(ctx1, ctx2))
161 hmac_final(HMAC_CTX *ctx,
unsigned char *
buf,
unsigned int *buf_len)
169 if (!HMAC_CTX_copy(
final, ctx)) {
174 HMAC_Final(
final,
buf, buf_len);
191 ossl_hmac_digest(
VALUE self)
194 unsigned int buf_len;
199 hmac_final(ctx, (
unsigned char *)
RSTRING_PTR(ret), &buf_len);
200 assert(buf_len <= EVP_MAX_MD_SIZE);
214 ossl_hmac_hexdigest(
VALUE self)
217 unsigned char buf[EVP_MAX_MD_SIZE];
218 unsigned int buf_len;
222 hmac_final(ctx, buf, &buf_len);
249 ossl_hmac_reset(
VALUE self)
280 unsigned int buf_len;
288 return rb_str_new((
const char *)buf, buf_len);
311 unsigned char buf[EVP_MAX_MD_SIZE];
312 unsigned int buf_len;
389 # warning >>> OpenSSL is compiled without HMAC support <<< 393 rb_warning(
"HMAC is not available: OpenSSL is compiled without HMAC.");
#define GetHMAC(obj, ctx)
#define RUBY_TYPED_FREE_IMMEDIATELY
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
void rb_str_set_len(VALUE, long)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
RUBY_EXTERN VALUE rb_cObject
void Init_ossl_hmac(void)
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
const EVP_MD * ossl_evp_get_digestbyname(VALUE obj)
unsigned char buf[MIME_BUF_SIZE]
void ossl_bin2hex(unsigned char *in, char *out, size_t inlen)
void rb_warning(const char *fmt,...)
void ossl_raise(VALUE exc, const char *fmt,...)
#define RTYPEDDATA_DATA(v)
#define RSTRING_LENINT(str)
#define rb_check_frozen(obj)
VALUE rb_define_module(const char *name)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_new(const char *, long)