ext/digest/sha2/sha2.h


DEFINITIONS

This source file includes following functions.


   1  /*
   2   * sha2.h
   3   *
   4   * Version 1.0.0beta1
   5   *
   6   * Written by Aaron D. Gifford <me@aarongifford.com>
   7   *
   8   * Copyright 2000 Aaron D. Gifford.  All rights reserved.
   9   *
  10   * Redistribution and use in source and binary forms, with or without
  11   * modification, are permitted provided that the following conditions
  12   * are met:
  13   * 1. Redistributions of source code must retain the above copyright
  14   *    notice, this list of conditions and the following disclaimer.
  15   * 2. Redistributions in binary form must reproduce the above copyright
  16   *    notice, this list of conditions and the following disclaimer in the
  17   *    documentation and/or other materials provided with the distribution.
  18   * 3. Neither the name of the copyright holder nor the names of contributors
  19   *    may be used to endorse or promote products derived from this software
  20   *    without specific prior written permission.
  21   * 
  22   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTOR(S) ``AS IS'' AND
  23   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25   * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE
  26   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32   * SUCH DAMAGE.
  33   *
  34   */
  35  
  36  /* $RoughId: sha2.h,v 1.3 2002/02/24 08:14:32 knu Exp $ */
  37  /* $Id: sha2.h,v 1.2 2002/02/24 08:20:22 knu Exp $ */
  38  
  39  #ifndef __SHA2_H__
  40  #define __SHA2_H__
  41  
  42  #ifdef __cplusplus
  43  extern "C" {
  44  #endif
  45  
  46  #include "defs.h"
  47  
  48  
  49  /*** SHA-256/384/512 Various Length Definitions ***********************/
  50  #define SHA256_BLOCK_LENGTH             64
  51  #define SHA256_DIGEST_LENGTH            32
  52  #define SHA256_DIGEST_STRING_LENGTH     (SHA256_DIGEST_LENGTH * 2 + 1)
  53  #define SHA384_BLOCK_LENGTH             128
  54  #define SHA384_DIGEST_LENGTH            48
  55  #define SHA384_DIGEST_STRING_LENGTH     (SHA384_DIGEST_LENGTH * 2 + 1)
  56  #define SHA512_BLOCK_LENGTH             128
  57  #define SHA512_DIGEST_LENGTH            64
  58  #define SHA512_DIGEST_STRING_LENGTH     (SHA512_DIGEST_LENGTH * 2 + 1)
  59  
  60  
  61  /*** SHA-256/384/512 Context Structures *******************************/
  62  
  63  typedef struct _SHA256_CTX {
  64          uint32_t        state[8];
  65          uint64_t        bitcount;
  66          uint8_t buffer[SHA256_BLOCK_LENGTH];
  67  } SHA256_CTX;
  68  typedef struct _SHA512_CTX {
  69          uint64_t        state[8];
  70          uint64_t        bitcount[2];
  71          uint8_t buffer[SHA512_BLOCK_LENGTH];
  72  } SHA512_CTX;
  73  
  74  typedef SHA512_CTX SHA384_CTX;
  75  
  76  
  77  #ifdef RUBY
  78  #define SHA256_Init             rb_Digest_SHA256_Init
  79  #define SHA256_Update           rb_Digest_SHA256_Update
  80  #define SHA256_Final            rb_Digest_SHA256_Final
  81  #define SHA256_End              rb_Digest_SHA256_End
  82  #define SHA256_Data             rb_Digest_SHA256_Data
  83  #define SHA256_File             rb_Digest_SHA256_File
  84  #define SHA256_Equal            rb_Digest_SHA256_Equal
  85  
  86  #define SHA384_Init             rb_Digest_SHA384_Init
  87  #define SHA384_Update           rb_Digest_SHA384_Update
  88  #define SHA384_Final            rb_Digest_SHA384_Final
  89  #define SHA384_End              rb_Digest_SHA384_End
  90  #define SHA384_Data             rb_Digest_SHA384_Data
  91  #define SHA384_File             rb_Digest_SHA384_File
  92  #define SHA384_Equal            rb_Digest_SHA384_Equal
  93  
  94  #define SHA512_Init             rb_Digest_SHA512_Init
  95  #define SHA512_Update           rb_Digest_SHA512_Update
  96  #define SHA512_Final            rb_Digest_SHA512_Final
  97  #define SHA512_End              rb_Digest_SHA512_End
  98  #define SHA512_Data             rb_Digest_SHA512_Data
  99  #define SHA512_File             rb_Digest_SHA512_File
 100  #define SHA512_Equal            rb_Digest_SHA512_Equal
 101  #endif
 102  
 103  /*** SHA-256/384/512 Function Prototypes ******************************/
 104  void SHA256_Init _((SHA256_CTX *));
 105  void SHA256_Update _((SHA256_CTX*, const uint8_t*, size_t));
 106  void SHA256_Final _((uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*));
 107  char* SHA256_End _((SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]));
 108  char* SHA256_Data _((const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]));
 109  char *SHA256_File _((char *, char *));
 110  int SHA256_Equal _((SHA256_CTX*, SHA256_CTX*));
 111  
 112  void SHA384_Init _((SHA384_CTX*));
 113  void SHA384_Update _((SHA384_CTX*, const uint8_t*, size_t));
 114  void SHA384_Final _((uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*));
 115  char* SHA384_End _((SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]));
 116  char* SHA384_Data _((const uint8_t*, size_t, char[SHA384_DIGEST_STRING_LENGTH]));
 117  char *SHA384_File _((char *, char *));
 118  int SHA384_Equal _((SHA384_CTX*, SHA384_CTX*));
 119  
 120  void SHA512_Init _((SHA512_CTX*));
 121  void SHA512_Update _((SHA512_CTX*, const uint8_t*, size_t));
 122  void SHA512_Final _((uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*));
 123  char* SHA512_End _((SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]));
 124  char* SHA512_Data _((const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]));
 125  char *SHA512_File _((char *, char *));
 126  int SHA512_Equal _((SHA512_CTX*, SHA512_CTX*));
 127  
 128  #ifdef  __cplusplus
 129  }
 130  #endif /* __cplusplus */
 131  
 132  #endif /* __SHA2_H__ */
 133