ext/digest/sha2/sha2init.c


DEFINITIONS

This source file includes following functions.
  1. FOREACH_BITLEN


   1  /* $RoughId: sha2init.c,v 1.3 2001/07/13 20:00:43 knu Exp $ */
   2  /* $Id: sha2init.c,v 1.2 2002/02/17 12:43:44 nobu Exp $ */
   3  
   4  #include "digest.h"
   5  #include "sha2.h"
   6  
   7  #define FOREACH_BITLEN(func)    func(256) func(384) func(512)
   8  
   9  #define DEFINE_ALGO_METADATA(bitlen) \
  10  static algo_t sha##bitlen = { \
  11      SHA##bitlen##_DIGEST_LENGTH, \
  12      sizeof(SHA##bitlen##_CTX), \
  13      (hash_init_func_t)SHA##bitlen##_Init, \
  14      (hash_update_func_t)SHA##bitlen##_Update, \
  15      (hash_end_func_t)SHA##bitlen##_End, \
  16      (hash_final_func_t)SHA##bitlen##_Final, \
  17      (hash_equal_func_t)SHA##bitlen##_Equal, \
  18  };
  19  
  20  FOREACH_BITLEN(DEFINE_ALGO_METADATA)
  21  
  22  void
  23  Init_sha2()
  24  {
  25      VALUE mDigest, cDigest_Base;
  26      ID id_metadata;
  27  
  28  #define DECLARE_ALGO_CLASS(bitlen) \
  29      VALUE cDigest_SHA##bitlen;
  30  
  31      FOREACH_BITLEN(DECLARE_ALGO_CLASS)
  32  
  33      rb_require("digest.so");
  34  
  35      id_metadata = rb_intern("metadata");
  36  
  37      mDigest = rb_path2class("Digest");
  38      cDigest_Base = rb_path2class("Digest::Base");
  39  
  40  #define DEFINE_ALGO_CLASS(bitlen) \
  41      cDigest_SHA##bitlen = rb_define_class_under(mDigest, "SHA" #bitlen, cDigest_Base); \
  42  \
  43      rb_cvar_set(cDigest_SHA##bitlen, id_metadata, \
  44                  Data_Wrap_Struct(rb_cObject, 0, 0, &sha##bitlen), Qtrue);
  45  
  46      FOREACH_BITLEN(DEFINE_ALGO_CLASS)
  47  }