This source file includes following definitions.
- hmac_hash
 
- GL_HMAC_FN
 
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 #include <string.h>
  18 
  19 #include "memxor.h"
  20 
  21 #define IPAD 0x36
  22 #define OPAD 0x5c
  23 
  24 
  25 #define _GLHMAC_CONCAT_(prefix, suffix) prefix##suffix
  26 #define _GLHMAC_CONCAT(prefix, suffix) _GLHMAC_CONCAT_ (prefix, suffix)
  27 
  28 #if GL_HMAC_NAME == 5
  29 # define HMAC_ALG md5
  30 #else
  31 # define HMAC_ALG _GLHMAC_CONCAT (sha, GL_HMAC_NAME)
  32 #endif
  33 
  34 #define GL_HMAC_CTX _GLHMAC_CONCAT (HMAC_ALG, _ctx)
  35 #define GL_HMAC_FN _GLHMAC_CONCAT (hmac_, HMAC_ALG)
  36 #define GL_HMAC_FN_INIT _GLHMAC_CONCAT (HMAC_ALG, _init_ctx)
  37 #define GL_HMAC_FN_BLOC _GLHMAC_CONCAT (HMAC_ALG, _process_block)
  38 #define GL_HMAC_FN_PROC _GLHMAC_CONCAT (HMAC_ALG, _process_bytes)
  39 #define GL_HMAC_FN_FINI _GLHMAC_CONCAT (HMAC_ALG, _finish_ctx)
  40 
  41 static void
  42 hmac_hash (const void *key, size_t keylen,
     
  43            const void *in, size_t inlen,
  44            int pad, void *resbuf)
  45 {
  46   struct GL_HMAC_CTX hmac_ctx;
  47   char block[GL_HMAC_BLOCKSIZE];
  48 
  49   memset (block, pad, sizeof block);
  50   memxor (block, key, keylen);
  51 
  52   GL_HMAC_FN_INIT (&hmac_ctx);
  53   GL_HMAC_FN_BLOC (block, sizeof block, &hmac_ctx);
  54   GL_HMAC_FN_PROC (in, inlen, &hmac_ctx);
  55   GL_HMAC_FN_FINI (&hmac_ctx, resbuf);
  56 }
  57 
  58 int
  59 GL_HMAC_FN (const void *key, size_t keylen,
     
  60             const void *in, size_t inlen, void *resbuf)
  61 {
  62   char optkeybuf[GL_HMAC_HASHSIZE];
  63   char innerhash[GL_HMAC_HASHSIZE];
  64 
  65   
  66   if (keylen > GL_HMAC_BLOCKSIZE)
  67     {
  68       struct GL_HMAC_CTX keyhash;
  69 
  70       GL_HMAC_FN_INIT (&keyhash);
  71       GL_HMAC_FN_PROC (key, keylen, &keyhash);
  72       GL_HMAC_FN_FINI (&keyhash, optkeybuf);
  73 
  74       key = optkeybuf;
  75       
  76 
  77       keylen = sizeof optkeybuf;
  78     }
  79 
  80   
  81   hmac_hash (key, keylen, in, inlen, IPAD, innerhash);
  82 
  83   
  84   hmac_hash (key, keylen, innerhash, sizeof innerhash, OPAD, resbuf);
  85 
  86   return 0;
  87 }