Ruby  2.1.10p492(2016-04-01revision54464)
sha2init.c
Go to the documentation of this file.
1 /* $RoughId: sha2init.c,v 1.3 2001/07/13 20:00:43 knu Exp $ */
2 /* $Id: sha2init.c 52797 2015-11-30 12:08:16Z usa $ */
3 
4 #include <ruby/ruby.h>
5 #include "../digest.h"
6 #if defined(SHA2_USE_OPENSSL)
7 #include "sha2ossl.h"
8 #else
9 #include "sha2.h"
10 #endif
11 
12 #define FOREACH_BITLEN(func) func(256) func(384) func(512)
13 
14 #define DEFINE_ALGO_METADATA(bitlen) \
15 static const rb_digest_metadata_t sha##bitlen = { \
16  RUBY_DIGEST_API_VERSION, \
17  SHA##bitlen##_DIGEST_LENGTH, \
18  SHA##bitlen##_BLOCK_LENGTH, \
19  sizeof(SHA##bitlen##_CTX), \
20  (rb_digest_hash_init_func_t)SHA##bitlen##_Init, \
21  (rb_digest_hash_update_func_t)SHA##bitlen##_Update, \
22  (rb_digest_hash_finish_func_t)SHA##bitlen##_Finish, \
23 };
24 
26 
27 /*
28  * Classes for calculating message digests using the SHA-256/384/512
29  * Secure Hash Algorithm(s) by NIST (the US' National Institute of
30  * Standards and Technology), described in FIPS PUB 180-2.
31  */
32 void
34 {
35  VALUE mDigest, cDigest_Base;
37 
38 #define DECLARE_ALGO_CLASS(bitlen) \
39  VALUE cDigest_SHA##bitlen;
40 
42 
43  rb_require("digest");
44 
45  id_metadata = rb_intern("metadata");
46 
47  mDigest = rb_path2class("Digest");
48  cDigest_Base = rb_path2class("Digest::Base");
49 
50 #define DEFINE_ALGO_CLASS(bitlen) \
51  cDigest_SHA##bitlen = rb_define_class_under(mDigest, "SHA" #bitlen, cDigest_Base); \
52 \
53  rb_ivar_set(cDigest_SHA##bitlen, id_metadata, \
54  Data_Wrap_Struct(rb_cObject, 0, 0, (void *)&sha##bitlen));
55 
57 }
#define DEFINE_ALGO_METADATA(bitlen)
Definition: sha2init.c:14
VALUE rb_require(const char *)
Definition: load.c:1036
VALUE rb_path2class(const char *)
Definition: variable.c:379
void Init_sha2()
Definition: sha2init.c:33
unsigned long ID
Definition: ripper.y:89
#define DEFINE_ALGO_CLASS(bitlen)
#define DECLARE_ALGO_CLASS(bitlen)
VP_EXPORT void
Definition: bigdecimal.c:5207
static ID id_metadata
Definition: digest.c:24
unsigned long VALUE
Definition: ripper.y:88
#define rb_intern(str)
#define FOREACH_BITLEN(func)
Definition: sha2init.c:12