pbkdf2.c

Basic pbkdf2 implementation
git clone git://git.finwo.net/lib/pbkdf2.c
Log | Files | Refs | README | LICENSE

pbkdf2.h (1135B)


      1 #ifndef __FINWO_PBKDF2_H__
      2 #define __FINWO_PBKDF2_H__
      3 
      4 #include <stddef.h>
      5 #include <stdint.h>
      6 
      7 enum pbkdf2_hash {
      8   PBKDF2_SHA1,
      9   PBKDF2_SHA256
     10 };
     11 
     12 struct sha1_ctx {
     13   uint32_t state[5];
     14   size_t datalen;
     15   uint64_t bitlen;
     16   uint8_t buffer[64];
     17 };
     18 
     19 struct sha256_ctx {
     20   uint32_t state[8];
     21   size_t datalen;
     22   uint64_t bitlen;
     23   uint8_t buffer[64];
     24 };
     25 
     26 void sha1_init(struct sha1_ctx *ctx);
     27 void sha1_update(struct sha1_ctx *ctx, const uint8_t *data, size_t len);
     28 void sha1_final(struct sha1_ctx *ctx, uint8_t *hash);
     29 
     30 void sha256_init(struct sha256_ctx *ctx);
     31 void sha256_update(struct sha256_ctx *ctx, const uint8_t *data, size_t len);
     32 void sha256_final(struct sha256_ctx *ctx, uint8_t *hash);
     33 
     34 void hmac_sha1(
     35   const uint8_t *key, size_t key_len,
     36   const uint8_t *data, size_t data_len,
     37   uint8_t *output
     38 );
     39 
     40 void hmac_sha256(
     41   const uint8_t *key, size_t key_len,
     42   const uint8_t *data, size_t data_len,
     43   uint8_t *output
     44 );
     45 
     46 void pbkdf2(
     47   const uint8_t *password, size_t password_len,
     48   const uint8_t *salt,     size_t salt_len,
     49   uint64_t iterations,
     50   enum pbkdf2_hash hash,
     51   uint8_t *output, size_t output_len
     52 );
     53 
     54 #endif