Ruby  1.9.3p448(2013-06-27revision41675)
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 26745 2010-02-24 00:31:37Z nobu $ */
3 
4 #include "digest.h"
5 #if defined(SHA2_USE_OPENSSL)
6 #include "sha2ossl.h"
7 #else
8 #include "sha2.h"
9 #endif
10 
11 #define FOREACH_BITLEN(func) func(256) func(384) func(512)
12 
13 #define DEFINE_ALGO_METADATA(bitlen) \
14 static const rb_digest_metadata_t sha##bitlen = { \
15  RUBY_DIGEST_API_VERSION, \
16  SHA##bitlen##_DIGEST_LENGTH, \
17  SHA##bitlen##_BLOCK_LENGTH, \
18  sizeof(SHA##bitlen##_CTX), \
19  (rb_digest_hash_init_func_t)SHA##bitlen##_Init, \
20  (rb_digest_hash_update_func_t)SHA##bitlen##_Update, \
21  (rb_digest_hash_finish_func_t)SHA##bitlen##_Finish, \
22 };
23 
25 
26 /*
27  * Classes for calculating message digests using the SHA-256/384/512
28  * Secure Hash Algorithm(s) by NIST (the US' National Institute of
29  * Standards and Technology), described in FIPS PUB 180-2.
30  */
31 void
33 {
34  VALUE mDigest, cDigest_Base;
36 
37 #define DECLARE_ALGO_CLASS(bitlen) \
38  VALUE cDigest_SHA##bitlen;
39 
41 
42  rb_require("digest");
43 
44  id_metadata = rb_intern("metadata");
45 
46  mDigest = rb_path2class("Digest");
47  cDigest_Base = rb_path2class("Digest::Base");
48 
49 #define DEFINE_ALGO_CLASS(bitlen) \
50  cDigest_SHA##bitlen = rb_define_class_under(mDigest, "SHA" #bitlen, cDigest_Base); \
51 \
52  rb_ivar_set(cDigest_SHA##bitlen, id_metadata, \
53  Data_Wrap_Struct(rb_cObject, 0, 0, (void *)&sha##bitlen));
54 
56 }
#define DEFINE_ALGO_METADATA(bitlen)
Definition: sha2init.c:13
VALUE rb_path2class(const char *)
Definition: variable.c:293
VALUE rb_require(const char *)
Definition: load.c:652
void Init_sha2()
Definition: sha2init.c:32
#define DEFINE_ALGO_CLASS(bitlen)
#define DECLARE_ALGO_CLASS(bitlen)
unsigned long ID
Definition: ruby.h:89
unsigned long VALUE
Definition: ruby.h:88
static ID id_metadata
Definition: digest.c:24
#define rb_intern(str)
#define FOREACH_BITLEN(func)
Definition: sha2init.c:11