ext/digest/sha2/sha2init.c

Go to the documentation of this file.
00001 /* $RoughId: sha2init.c,v 1.3 2001/07/13 20:00:43 knu Exp $ */
00002 /* $Id: sha2init.c 28341 2010-06-16 09:38:14Z knu $ */
00003 
00004 #include "../digest.h"
00005 #if defined(SHA2_USE_OPENSSL)
00006 #include "sha2ossl.h"
00007 #else
00008 #include "sha2.h"
00009 #endif
00010 
00011 #define FOREACH_BITLEN(func)    func(256) func(384) func(512)
00012 
00013 #define DEFINE_ALGO_METADATA(bitlen) \
00014 static const rb_digest_metadata_t sha##bitlen = { \
00015     RUBY_DIGEST_API_VERSION, \
00016     SHA##bitlen##_DIGEST_LENGTH, \
00017     SHA##bitlen##_BLOCK_LENGTH, \
00018     sizeof(SHA##bitlen##_CTX), \
00019     (rb_digest_hash_init_func_t)SHA##bitlen##_Init, \
00020     (rb_digest_hash_update_func_t)SHA##bitlen##_Update, \
00021     (rb_digest_hash_finish_func_t)SHA##bitlen##_Finish, \
00022 };
00023 
00024 FOREACH_BITLEN(DEFINE_ALGO_METADATA)
00025 
00026 /*
00027  * Classes for calculating message digests using the SHA-256/384/512
00028  * Secure Hash Algorithm(s) by NIST (the US' National Institute of
00029  * Standards and Technology), described in FIPS PUB 180-2.
00030  */
00031 void
00032 Init_sha2()
00033 {
00034     VALUE mDigest, cDigest_Base;
00035     ID id_metadata;
00036 
00037 #define DECLARE_ALGO_CLASS(bitlen) \
00038     VALUE cDigest_SHA##bitlen;
00039 
00040     FOREACH_BITLEN(DECLARE_ALGO_CLASS)
00041 
00042     rb_require("digest");
00043 
00044     id_metadata = rb_intern("metadata");
00045 
00046     mDigest = rb_path2class("Digest");
00047     cDigest_Base = rb_path2class("Digest::Base");
00048 
00049 #define DEFINE_ALGO_CLASS(bitlen) \
00050     cDigest_SHA##bitlen = rb_define_class_under(mDigest, "SHA" #bitlen, cDigest_Base); \
00051 \
00052     rb_ivar_set(cDigest_SHA##bitlen, id_metadata, \
00053       Data_Wrap_Struct(rb_cObject, 0, 0, (void *)&sha##bitlen));
00054 
00055     FOREACH_BITLEN(DEFINE_ALGO_CLASS)
00056 }
00057 

Generated on Wed Aug 10 09:16:57 2011 for Ruby by  doxygen 1.4.7