mirror of
https://github.com/cryb-to/cryb-to.git
synced 2024-11-25 15:15:42 +00:00
Clean up headers and typedefs.
Fix context length in the algorithm descriptors. Expose the block length and include it in the algorithm descriptors. Complete the list of available digest algorithms.
This commit is contained in:
parent
4c17e0f386
commit
b0ff5af2ba
21 changed files with 122 additions and 79 deletions
|
@ -9,6 +9,7 @@ cryb_HEADERS = \
|
||||||
digest.h \
|
digest.h \
|
||||||
hmac.h \
|
hmac.h \
|
||||||
hotp.h \
|
hotp.h \
|
||||||
|
md.h \
|
||||||
md2.h \
|
md2.h \
|
||||||
md4.h \
|
md4.h \
|
||||||
md5.h \
|
md5.h \
|
||||||
|
@ -18,6 +19,7 @@ cryb_HEADERS = \
|
||||||
rand.h \
|
rand.h \
|
||||||
rfc3986.h \
|
rfc3986.h \
|
||||||
rfc4648.h \
|
rfc4648.h \
|
||||||
|
sha.h \
|
||||||
sha1.h \
|
sha1.h \
|
||||||
sha256.h \
|
sha256.h \
|
||||||
sha384.h \
|
sha384.h \
|
||||||
|
|
|
@ -27,33 +27,29 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* Author: Dag-Erling Smørgrav <des@des.no>
|
|
||||||
* Sponsor: the University of Oslo
|
|
||||||
*
|
|
||||||
* $Cryb$
|
* $Cryb$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CRYB_DIGEST_H_INCLUDED
|
#ifndef CRYB_DIGEST_H_INCLUDED
|
||||||
#define CRYB_DIGEST_H_INCLUDED
|
#define CRYB_DIGEST_H_INCLUDED
|
||||||
|
|
||||||
|
#define digest_ctx cryb_digest_ctx
|
||||||
#define digest_init_func cryb_digest_init_func
|
#define digest_init_func cryb_digest_init_func
|
||||||
#define digest_update_func cryb_digest_update_func
|
#define digest_update_func cryb_digest_update_func
|
||||||
#define digest_final_func cryb_digest_final_func
|
#define digest_final_func cryb_digest_final_func
|
||||||
#define digest_complete_func cryb_digest_complete_func
|
#define digest_complete_func cryb_digest_complete_func
|
||||||
#define digest_algorithm cryb_digest_algorithm
|
#define digest_algorithm cryb_digest_algorithm
|
||||||
#define digest_init cryb_digest_init
|
|
||||||
#define digest_update cryb_digest_update
|
|
||||||
#define digest_final cryb_digest_final
|
|
||||||
#define digest_complete cryb_digest_complete
|
|
||||||
|
|
||||||
typedef void (*digest_init_func)(void *);
|
typedef void digest_ctx;
|
||||||
typedef void (*digest_update_func)(void *, const void *, size_t);
|
typedef void (*digest_init_func)(digest_ctx *);
|
||||||
typedef void (*digest_final_func)(void *, void *);
|
typedef void (*digest_update_func)(digest_ctx *, const void *, size_t);
|
||||||
|
typedef void (*digest_final_func)(digest_ctx *, void *);
|
||||||
typedef int (*digest_complete_func)(const void *, size_t, void *);
|
typedef int (*digest_complete_func)(const void *, size_t, void *);
|
||||||
|
|
||||||
typedef struct digest_algorithm {
|
typedef struct {
|
||||||
const char *name; /* algorithm name */
|
const char *name; /* algorithm name */
|
||||||
size_t contextlen; /* size of context structure */
|
size_t contextlen; /* size of context structure */
|
||||||
|
size_t blocklen; /* block length */
|
||||||
size_t digestlen; /* length of the digest */
|
size_t digestlen; /* length of the digest */
|
||||||
digest_init_func init; /* initialization method */
|
digest_init_func init; /* initialization method */
|
||||||
digest_update_func update; /* update method */
|
digest_update_func update; /* update method */
|
||||||
|
@ -61,9 +57,17 @@ typedef struct digest_algorithm {
|
||||||
digest_complete_func complete; /* one-shot method */
|
digest_complete_func complete; /* one-shot method */
|
||||||
} digest_algorithm;
|
} digest_algorithm;
|
||||||
|
|
||||||
void *digest_init(const char *);
|
#define get_digest_algorithm cryb_get_digest_algorithm
|
||||||
void digest_update(void *, const void *, size_t);
|
|
||||||
void digest_final(void *, void *);
|
const digest_algorithm *get_digest_algorithm(const char *);
|
||||||
int digest_complete(const char *, const void *, size_t, void *);
|
|
||||||
|
#define digest_init(alg, ctx) \
|
||||||
|
(alg)->init((ctx))
|
||||||
|
#define digest_update(alg, ctx, buf, len) \
|
||||||
|
(alg)->update((ctx), (buf), (len))
|
||||||
|
#define digest_final(alg, ctx, md) \
|
||||||
|
(alg)->final((ctx), (md))
|
||||||
|
#define digest_complete(alg, buf, len, md) \
|
||||||
|
(alg)->update((buf), (len), (md))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -36,10 +36,12 @@
|
||||||
#ifndef CRYB_HMAC_H_INCLUDED
|
#ifndef CRYB_HMAC_H_INCLUDED
|
||||||
#define CRYB_HMAC_H_INCLUDED
|
#define CRYB_HMAC_H_INCLUDED
|
||||||
|
|
||||||
|
#include <cryb/sha1.h>
|
||||||
|
|
||||||
#define HMAC_LEN 20
|
#define HMAC_LEN 20
|
||||||
|
|
||||||
typedef struct hmac_ctx {
|
typedef struct {
|
||||||
struct sha1_ctx sha1_ctx;
|
sha1_ctx sha1_ctx;
|
||||||
uint8_t key[64];
|
uint8_t key[64];
|
||||||
size_t keylen;
|
size_t keylen;
|
||||||
} hmac_ctx;
|
} hmac_ctx;
|
||||||
|
|
4
include/cryb/md.h
Normal file
4
include/cryb/md.h
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/* $Cryb$ */
|
||||||
|
#include <md2.h>
|
||||||
|
#include <md4.h>
|
||||||
|
#include <md5.h>
|
|
@ -32,6 +32,9 @@
|
||||||
#ifndef CRYB_MD2_H_INCLUDED
|
#ifndef CRYB_MD2_H_INCLUDED
|
||||||
#define CRYB_MD2_H_INCLUDED
|
#define CRYB_MD2_H_INCLUDED
|
||||||
|
|
||||||
|
#include <cryb/digest.h>
|
||||||
|
|
||||||
|
#define MD2_BLOCK_LEN 16
|
||||||
#define MD2_DIGEST_LEN 16
|
#define MD2_DIGEST_LEN 16
|
||||||
|
|
||||||
#define md2_digest cryb_md2_digest
|
#define md2_digest cryb_md2_digest
|
||||||
|
@ -41,7 +44,7 @@
|
||||||
#define md2_final cryb_md2_final
|
#define md2_final cryb_md2_final
|
||||||
#define md2_complete cryb_md2_complete
|
#define md2_complete cryb_md2_complete
|
||||||
|
|
||||||
extern struct digest_algorithm md2_digest;
|
extern digest_algorithm md2_algorithm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief MD2 context structure
|
* \brief MD2 context structure
|
||||||
|
@ -55,8 +58,7 @@ typedef struct
|
||||||
unsigned char ipad[64]; /*!< HMAC: inner padding */
|
unsigned char ipad[64]; /*!< HMAC: inner padding */
|
||||||
unsigned char opad[64]; /*!< HMAC: outer padding */
|
unsigned char opad[64]; /*!< HMAC: outer padding */
|
||||||
int left; /*!< amount of data in buffer */
|
int left; /*!< amount of data in buffer */
|
||||||
}
|
} md2_ctx;
|
||||||
md2_ctx;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
@ -32,6 +32,9 @@
|
||||||
#ifndef CRYB_MD4_H_INCLUDED
|
#ifndef CRYB_MD4_H_INCLUDED
|
||||||
#define CRYB_MD4_H_INCLUDED
|
#define CRYB_MD4_H_INCLUDED
|
||||||
|
|
||||||
|
#include <cryb/digest.h>
|
||||||
|
|
||||||
|
#define MD4_BLOCK_LEN 64
|
||||||
#define MD4_DIGEST_LEN 16
|
#define MD4_DIGEST_LEN 16
|
||||||
|
|
||||||
#define md4_digest cryb_md4_digest
|
#define md4_digest cryb_md4_digest
|
||||||
|
@ -41,7 +44,7 @@
|
||||||
#define md4_final cryb_md4_final
|
#define md4_final cryb_md4_final
|
||||||
#define md4_complete cryb_md4_complete
|
#define md4_complete cryb_md4_complete
|
||||||
|
|
||||||
extern struct digest_algorithm md4_digest;
|
extern digest_algorithm md4_digest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief MD4 context structure
|
* \brief MD4 context structure
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
#ifndef CRYB_MD5_H_INCLUDED
|
#ifndef CRYB_MD5_H_INCLUDED
|
||||||
#define CRYB_MD5_H_INCLUDED
|
#define CRYB_MD5_H_INCLUDED
|
||||||
|
|
||||||
|
#include <cryb/digest.h>
|
||||||
|
|
||||||
|
#define MD5_BLOCK_LEN 64
|
||||||
#define MD5_DIGEST_LEN 16
|
#define MD5_DIGEST_LEN 16
|
||||||
|
|
||||||
#define md5_digest cryb_md5_digest
|
#define md5_digest cryb_md5_digest
|
||||||
|
@ -45,9 +48,9 @@
|
||||||
#define md5_final cryb_md5_final
|
#define md5_final cryb_md5_final
|
||||||
#define md5_complete cryb_md5_complete
|
#define md5_complete cryb_md5_complete
|
||||||
|
|
||||||
extern struct digest_algorithm md5_digest;
|
extern digest_algorithm md5_digest;
|
||||||
|
|
||||||
typedef struct md5_ctx {
|
typedef struct {
|
||||||
uint8_t block[64];
|
uint8_t block[64];
|
||||||
size_t blocklen;
|
size_t blocklen;
|
||||||
uint64_t bitlen;
|
uint64_t bitlen;
|
||||||
|
|
5
include/cryb/sha.h
Normal file
5
include/cryb/sha.h
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
/* $Cryb$ */
|
||||||
|
#include <cryb/sha1.h>
|
||||||
|
#include <cryb/sha256.h>
|
||||||
|
#include <cryb/sha384.h>
|
||||||
|
#include <cryb/sha512.h>
|
|
@ -36,6 +36,9 @@
|
||||||
#ifndef CRYB_SHA1_H_INCLUDED
|
#ifndef CRYB_SHA1_H_INCLUDED
|
||||||
#define CRYB_SHA1_H_INCLUDED
|
#define CRYB_SHA1_H_INCLUDED
|
||||||
|
|
||||||
|
#include <cryb/digest.h>
|
||||||
|
|
||||||
|
#define SHA1_BLOCK_LEN 64
|
||||||
#define SHA1_DIGEST_LEN 20
|
#define SHA1_DIGEST_LEN 20
|
||||||
|
|
||||||
#define sha1_digest cryb_sha1_digest
|
#define sha1_digest cryb_sha1_digest
|
||||||
|
@ -45,16 +48,16 @@
|
||||||
#define sha1_final cryb_sha1_final
|
#define sha1_final cryb_sha1_final
|
||||||
#define sha1_complete cryb_sha1_complete
|
#define sha1_complete cryb_sha1_complete
|
||||||
|
|
||||||
extern struct digest_algorithm sha1_digest;
|
extern digest_algorithm sha1_digest;
|
||||||
|
|
||||||
typedef struct sha1_ctx {
|
typedef struct {
|
||||||
uint8_t block[64];
|
uint8_t block[64];
|
||||||
size_t blocklen;
|
size_t blocklen;
|
||||||
uint64_t bitlen;
|
uint64_t bitlen;
|
||||||
uint32_t h[5], k[4];
|
uint32_t h[5], k[4];
|
||||||
} sha1_ctx;
|
} sha1_ctx;
|
||||||
|
|
||||||
extern struct digest_algorithm sha1_algorithm;
|
extern digest_algorithm sha1_algorithm;
|
||||||
|
|
||||||
void sha1_init(sha1_ctx *);
|
void sha1_init(sha1_ctx *);
|
||||||
void sha1_update(sha1_ctx *, const void *, size_t);
|
void sha1_update(sha1_ctx *, const void *, size_t);
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
#ifndef CRYB_SHA256_H_INCLUDED
|
#ifndef CRYB_SHA256_H_INCLUDED
|
||||||
#define CRYB_SHA256_H_INCLUDED
|
#define CRYB_SHA256_H_INCLUDED
|
||||||
|
|
||||||
|
#include <cryb/digest.h>
|
||||||
|
|
||||||
|
#define SHA256_BLOCK_LEN 64
|
||||||
#define SHA256_DIGEST_LEN 32
|
#define SHA256_DIGEST_LEN 32
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -42,7 +45,7 @@
|
||||||
#define sha256_final cryb_sha256_final
|
#define sha256_final cryb_sha256_final
|
||||||
#define sha256_complete cryb_sha256_complete
|
#define sha256_complete cryb_sha256_complete
|
||||||
|
|
||||||
extern struct digest_algorithm sha256_digest;
|
extern digest_algorithm sha256_digest;
|
||||||
|
|
||||||
#define hmac_sha256_init cryb_hmac_sha256_init
|
#define hmac_sha256_init cryb_hmac_sha256_init
|
||||||
#define hmac_sha256_update cryb_hmac_sha256_update
|
#define hmac_sha256_update cryb_hmac_sha256_update
|
||||||
|
|
|
@ -32,6 +32,9 @@
|
||||||
#ifndef CRYB_SHA384_H_INCLUDED
|
#ifndef CRYB_SHA384_H_INCLUDED
|
||||||
#define CRYB_SHA384_H_INCLUDED
|
#define CRYB_SHA384_H_INCLUDED
|
||||||
|
|
||||||
|
#include <cryb/digest.h>
|
||||||
|
|
||||||
|
#define SHA384_BLOCK_LEN 128
|
||||||
#define SHA384_DIGEST_LEN 48
|
#define SHA384_DIGEST_LEN 48
|
||||||
|
|
||||||
#define sha384_digest cryb_sha384_digest
|
#define sha384_digest cryb_sha384_digest
|
||||||
|
@ -41,7 +44,7 @@
|
||||||
#define sha384_final cryb_sha384_final
|
#define sha384_final cryb_sha384_final
|
||||||
#define sha384_complete cryb_sha384_complete
|
#define sha384_complete cryb_sha384_complete
|
||||||
|
|
||||||
extern struct digest_algorithm sha384_digest;
|
extern digest_algorithm sha384_digest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief SHA-384 context structure
|
* \brief SHA-384 context structure
|
||||||
|
|
|
@ -32,6 +32,9 @@
|
||||||
#ifndef CRYB_SHA512_H_INCLUDED
|
#ifndef CRYB_SHA512_H_INCLUDED
|
||||||
#define CRYB_SHA512_H_INCLUDED
|
#define CRYB_SHA512_H_INCLUDED
|
||||||
|
|
||||||
|
#include <cryb/digest.h>
|
||||||
|
|
||||||
|
#define SHA512_BLOCK_LEN 128
|
||||||
#define SHA512_DIGEST_LEN 64
|
#define SHA512_DIGEST_LEN 64
|
||||||
|
|
||||||
#define sha512_digest cryb_sha512_digest
|
#define sha512_digest cryb_sha512_digest
|
||||||
|
@ -41,7 +44,7 @@
|
||||||
#define sha512_final cryb_sha512_final
|
#define sha512_final cryb_sha512_final
|
||||||
#define sha512_complete cryb_sha512_complete
|
#define sha512_complete cryb_sha512_complete
|
||||||
|
|
||||||
extern struct digest_algorithm sha512_digest;
|
extern digest_algorithm sha512_digest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief SHA-512 context structure
|
* \brief SHA-512 context structure
|
||||||
|
|
|
@ -37,27 +37,36 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <cryb/digest.h>
|
#include <cryb/md2.h>
|
||||||
|
#include <cryb/md4.h>
|
||||||
#include <cryb/md5.h>
|
#include <cryb/md5.h>
|
||||||
#include <cryb/sha1.h>
|
#include <cryb/sha1.h>
|
||||||
|
#include <cryb/sha256.h>
|
||||||
|
#include <cryb/sha384.h>
|
||||||
|
#include <cryb/sha512.h>
|
||||||
|
|
||||||
static const struct digest_algorithm **cryb_digest_algorithms;
|
static const digest_algorithm **cryb_digest_algorithms;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cryb_init_digest_algorithms(void)
|
init_digest_algorithms(void)
|
||||||
{
|
{
|
||||||
static const struct digest_algorithm *algorithms[] = {
|
static const digest_algorithm *algorithms[] = {
|
||||||
&cryb_md5_algorithm,
|
&md2_algorithm,
|
||||||
&cryb_sha1_algorithm,
|
&md4_algorithm,
|
||||||
|
&md5_algorithm,
|
||||||
|
&sha1_algorithm,
|
||||||
|
&sha256_algorithm,
|
||||||
|
&sha384_algorithm,
|
||||||
|
&sha512_algorithm,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
cryb_digest_algorithms = algorithms;
|
cryb_digest_algorithms = algorithms;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct digest_algorithm *
|
const digest_algorithm *
|
||||||
cryb_digest_algorithm(const char *name)
|
get_digest_algorithm(const char *name)
|
||||||
{
|
{
|
||||||
const struct digest_algorithm **algp;
|
const digest_algorithm **algp;
|
||||||
|
|
||||||
if (cryb_digest_algorithms == NULL)
|
if (cryb_digest_algorithms == NULL)
|
||||||
cryb_init_digest_algorithms();
|
cryb_init_digest_algorithms();
|
||||||
|
@ -66,4 +75,3 @@ cryb_digest_algorithm(const char *name)
|
||||||
return (*algp);
|
return (*algp);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <cryb/digest.h>
|
|
||||||
#include <cryb/md2.h>
|
#include <cryb/md2.h>
|
||||||
|
|
||||||
static const unsigned char PI_SUBST[256] =
|
static const unsigned char PI_SUBST[256] =
|
||||||
|
@ -246,9 +245,10 @@ void md2_hmac_complete( unsigned char *key, int keylen, unsigned char *input, in
|
||||||
memset( &ctx, 0, sizeof( md2_ctx ) );
|
memset( &ctx, 0, sizeof( md2_ctx ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
struct digest_algorithm md2_digest = {
|
digest_algorithm md2_algorithm = {
|
||||||
.name = "md2",
|
.name = "md2",
|
||||||
.contextlen = sizeof md2_digest,
|
.contextlen = sizeof(md2_ctx),
|
||||||
|
.blocklen = MD2_BLOCK_LEN,
|
||||||
.digestlen = MD2_DIGEST_LEN,
|
.digestlen = MD2_DIGEST_LEN,
|
||||||
.init = (digest_init_func)md2_init,
|
.init = (digest_init_func)md2_init,
|
||||||
.update = (digest_update_func)md2_update,
|
.update = (digest_update_func)md2_update,
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <cryb/digest.h>
|
|
||||||
#include <cryb/md4.h>
|
#include <cryb/md4.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -345,9 +344,10 @@ void md4_hmac_complete( unsigned char *key, int keylen, unsigned char *input, in
|
||||||
memset( &ctx, 0, sizeof( md4_ctx ) );
|
memset( &ctx, 0, sizeof( md4_ctx ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
struct digest_algorithm md4_digest = {
|
digest_algorithm md4_algorithm = {
|
||||||
.name = "md4",
|
.name = "md4",
|
||||||
.contextlen = sizeof md4_digest,
|
.contextlen = sizeof(md4_ctx),
|
||||||
|
.blocklen = MD4_BLOCK_LEN,
|
||||||
.digestlen = MD4_DIGEST_LEN,
|
.digestlen = MD4_DIGEST_LEN,
|
||||||
.init = (digest_init_func)md4_init,
|
.init = (digest_init_func)md4_init,
|
||||||
.update = (digest_update_func)md4_update,
|
.update = (digest_update_func)md4_update,
|
||||||
|
|
|
@ -47,7 +47,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <cryb/digest.h>
|
|
||||||
#include <cryb/bitwise.h>
|
#include <cryb/bitwise.h>
|
||||||
#include <cryb/md5.h>
|
#include <cryb/md5.h>
|
||||||
|
|
||||||
|
@ -76,7 +75,7 @@ static const uint32_t md5_k[64] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
md5_init(struct md5_ctx *ctx)
|
md5_init(md5_ctx *ctx)
|
||||||
{
|
{
|
||||||
|
|
||||||
memset(ctx, 0, sizeof *ctx);
|
memset(ctx, 0, sizeof *ctx);
|
||||||
|
@ -112,7 +111,7 @@ md5_init(struct md5_ctx *ctx)
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
md5_compute(struct md5_ctx *ctx, const uint8_t *block)
|
md5_compute(md5_ctx *ctx, const uint8_t *block)
|
||||||
{
|
{
|
||||||
uint32_t w[16], a, b, c, d;
|
uint32_t w[16], a, b, c, d;
|
||||||
int i;
|
int i;
|
||||||
|
@ -203,7 +202,7 @@ md5_compute(struct md5_ctx *ctx, const uint8_t *block)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
md5_update(struct md5_ctx *ctx, const void *buf, size_t len)
|
md5_update(md5_ctx *ctx, const void *buf, size_t len)
|
||||||
{
|
{
|
||||||
size_t copylen;
|
size_t copylen;
|
||||||
|
|
||||||
|
@ -230,7 +229,7 @@ md5_update(struct md5_ctx *ctx, const void *buf, size_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
md5_final(struct md5_ctx *ctx, void *digest)
|
md5_final(md5_ctx *ctx, void *digest)
|
||||||
{
|
{
|
||||||
|
|
||||||
ctx->block[ctx->blocklen++] = 0x80;
|
ctx->block[ctx->blocklen++] = 0x80;
|
||||||
|
@ -252,16 +251,17 @@ md5_final(struct md5_ctx *ctx, void *digest)
|
||||||
void
|
void
|
||||||
md5_complete(const void *buf, size_t len, void *digest)
|
md5_complete(const void *buf, size_t len, void *digest)
|
||||||
{
|
{
|
||||||
struct md5_ctx ctx;
|
md5_ctx ctx;
|
||||||
|
|
||||||
md5_init(&ctx);
|
md5_init(&ctx);
|
||||||
md5_update(&ctx, buf, len);
|
md5_update(&ctx, buf, len);
|
||||||
md5_final(&ctx, digest);
|
md5_final(&ctx, digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct digest_algorithm md5_digest = {
|
digest_algorithm md5_digest = {
|
||||||
.name = "md5",
|
.name = "md5",
|
||||||
.contextlen = sizeof md5_digest,
|
.contextlen = sizeof(md5_ctx),
|
||||||
|
.blocklen = MD5_BLOCK_LEN,
|
||||||
.digestlen = MD5_DIGEST_LEN,
|
.digestlen = MD5_DIGEST_LEN,
|
||||||
.init = (digest_init_func)md5_init,
|
.init = (digest_init_func)md5_init,
|
||||||
.update = (digest_update_func)md5_update,
|
.update = (digest_update_func)md5_update,
|
||||||
|
|
|
@ -47,10 +47,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <cryb/digest.h>
|
|
||||||
#include <cryb/bitwise.h>
|
#include <cryb/bitwise.h>
|
||||||
|
|
||||||
#include <cryb/digest.h>
|
|
||||||
#include <cryb/sha1.h>
|
#include <cryb/sha1.h>
|
||||||
|
|
||||||
static uint32_t sha1_h[5] = {
|
static uint32_t sha1_h[5] = {
|
||||||
|
@ -62,7 +59,7 @@ static uint32_t sha1_k[4] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
sha1_init(struct sha1_ctx *ctx)
|
sha1_init(sha1_ctx *ctx)
|
||||||
{
|
{
|
||||||
|
|
||||||
memset(ctx, 0, sizeof *ctx);
|
memset(ctx, 0, sizeof *ctx);
|
||||||
|
@ -71,7 +68,7 @@ sha1_init(struct sha1_ctx *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sha1_compute(struct sha1_ctx *ctx, const uint8_t *block)
|
sha1_compute(sha1_ctx *ctx, const uint8_t *block)
|
||||||
{
|
{
|
||||||
uint32_t w[80], a, b, c, d, e, f, temp;
|
uint32_t w[80], a, b, c, d, e, f, temp;
|
||||||
|
|
||||||
|
@ -113,7 +110,7 @@ sha1_compute(struct sha1_ctx *ctx, const uint8_t *block)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sha1_update(struct sha1_ctx *ctx, const void *buf, size_t len)
|
sha1_update(sha1_ctx *ctx, const void *buf, size_t len)
|
||||||
{
|
{
|
||||||
size_t copylen;
|
size_t copylen;
|
||||||
|
|
||||||
|
@ -140,7 +137,7 @@ sha1_update(struct sha1_ctx *ctx, const void *buf, size_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sha1_final(struct sha1_ctx *ctx, void *digest)
|
sha1_final(sha1_ctx *ctx, void *digest)
|
||||||
{
|
{
|
||||||
uint32_t hi, lo;
|
uint32_t hi, lo;
|
||||||
|
|
||||||
|
@ -165,16 +162,17 @@ sha1_final(struct sha1_ctx *ctx, void *digest)
|
||||||
void
|
void
|
||||||
sha1_complete(const void *buf, size_t len, void *digest)
|
sha1_complete(const void *buf, size_t len, void *digest)
|
||||||
{
|
{
|
||||||
struct sha1_ctx ctx;
|
sha1_ctx ctx;
|
||||||
|
|
||||||
sha1_init(&ctx);
|
sha1_init(&ctx);
|
||||||
sha1_update(&ctx, buf, len);
|
sha1_update(&ctx, buf, len);
|
||||||
sha1_final(&ctx, digest);
|
sha1_final(&ctx, digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct digest_algorithm sha1_digest = {
|
digest_algorithm sha1_digest = {
|
||||||
.name = "sha1",
|
.name = "sha1",
|
||||||
.contextlen = sizeof sha1_digest,
|
.contextlen = sizeof sha1_digest,
|
||||||
|
.blocklen = SHA1_BLOCK_LEN,
|
||||||
.digestlen = SHA1_DIGEST_LEN,
|
.digestlen = SHA1_DIGEST_LEN,
|
||||||
.init = (digest_init_func)sha1_init,
|
.init = (digest_init_func)sha1_init,
|
||||||
.update = (digest_update_func)sha1_update,
|
.update = (digest_update_func)sha1_update,
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <cryb/digest.h>
|
|
||||||
#include <cryb/sha256.h>
|
#include <cryb/sha256.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -466,9 +465,10 @@ pbkdf2_sha256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt,
|
||||||
memset(&PShctx, 0, sizeof(hmac_sha256_ctx));
|
memset(&PShctx, 0, sizeof(hmac_sha256_ctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct digest_algorithm sha256_digest = {
|
digest_algorithm sha256_digest = {
|
||||||
.name = "sha256",
|
.name = "sha256",
|
||||||
.contextlen = sizeof sha256_digest,
|
.contextlen = sizeof sha256_digest,
|
||||||
|
.blocklen = SHA256_BLOCK_LEN,
|
||||||
.digestlen = SHA256_DIGEST_LEN,
|
.digestlen = SHA256_DIGEST_LEN,
|
||||||
.init = (digest_init_func)sha256_init,
|
.init = (digest_init_func)sha256_init,
|
||||||
.update = (digest_update_func)sha256_update,
|
.update = (digest_update_func)sha256_update,
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <cryb/digest.h>
|
|
||||||
#include <cryb/sha384.h>
|
#include <cryb/sha384.h>
|
||||||
|
|
||||||
static int is384 = 1;
|
static int is384 = 1;
|
||||||
|
@ -408,9 +407,10 @@ void sha384_hmac_complete( unsigned char *key, int keylen,
|
||||||
memset( &ctx, 0, sizeof( sha384_ctx ) );
|
memset( &ctx, 0, sizeof( sha384_ctx ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
struct digest_algorithm sha384_digest = {
|
digest_algorithm sha384_digest = {
|
||||||
.name = "sha384",
|
.name = "sha384",
|
||||||
.contextlen = sizeof sha384_digest,
|
.contextlen = sizeof sha384_digest,
|
||||||
|
.blocklen = SHA384_BLOCK_LEN,
|
||||||
.digestlen = SHA384_DIGEST_LEN,
|
.digestlen = SHA384_DIGEST_LEN,
|
||||||
.init = (digest_init_func)sha384_init,
|
.init = (digest_init_func)sha384_init,
|
||||||
.update = (digest_update_func)sha384_update,
|
.update = (digest_update_func)sha384_update,
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <cryb/digest.h>
|
|
||||||
#include <cryb/sha512.h>
|
#include <cryb/sha512.h>
|
||||||
|
|
||||||
static int is384 = 0;
|
static int is384 = 0;
|
||||||
|
@ -408,9 +407,10 @@ void sha512_hmac_complete( unsigned char *key, int keylen,
|
||||||
memset( &ctx, 0, sizeof( sha512_ctx ) );
|
memset( &ctx, 0, sizeof( sha512_ctx ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
struct digest_algorithm sha512_digest = {
|
digest_algorithm sha512_digest = {
|
||||||
.name = "sha512",
|
.name = "sha512",
|
||||||
.contextlen = sizeof sha512_digest,
|
.contextlen = sizeof sha512_digest,
|
||||||
|
.blocklen = SHA512_BLOCK_LEN,
|
||||||
.digestlen = SHA512_DIGEST_LEN,
|
.digestlen = SHA512_DIGEST_LEN,
|
||||||
.init = (digest_init_func)sha512_init,
|
.init = (digest_init_func)sha512_init,
|
||||||
.update = (digest_update_func)sha512_update,
|
.update = (digest_update_func)sha512_update,
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
#include <cryb/hmac.h>
|
#include <cryb/hmac.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
hmac_init(struct hmac_ctx *ctx, const uint8_t *key, size_t keylen)
|
hmac_init(hmac_ctx *ctx, const uint8_t *key, size_t keylen)
|
||||||
{
|
{
|
||||||
uint8_t ipad[64];
|
uint8_t ipad[64];
|
||||||
|
|
||||||
|
@ -77,14 +77,14 @@ hmac_init(struct hmac_ctx *ctx, const uint8_t *key, size_t keylen)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
hmac_update(struct hmac_ctx *ctx, const uint8_t *buf, size_t len)
|
hmac_update(hmac_ctx *ctx, const uint8_t *buf, size_t len)
|
||||||
{
|
{
|
||||||
|
|
||||||
sha1_update(&ctx->sha1_ctx, buf, len);
|
sha1_update(&ctx->sha1_ctx, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
hmac_final(struct hmac_ctx *ctx, uint8_t *mac)
|
hmac_final(hmac_ctx *ctx, uint8_t *mac)
|
||||||
{
|
{
|
||||||
uint8_t digest[20], opad[64];
|
uint8_t digest[20], opad[64];
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ void
|
||||||
hmac_complete(const uint8_t *key, size_t keylen,
|
hmac_complete(const uint8_t *key, size_t keylen,
|
||||||
const uint8_t *buf, size_t len, uint8_t *mac)
|
const uint8_t *buf, size_t len, uint8_t *mac)
|
||||||
{
|
{
|
||||||
struct hmac_ctx ctx;
|
hmac_ctx ctx;
|
||||||
|
|
||||||
hmac_init(&ctx, key, keylen);
|
hmac_init(&ctx, key, keylen);
|
||||||
hmac_update(&ctx, buf, len);
|
hmac_update(&ctx, buf, len);
|
||||||
|
|
Loading…
Reference in a new issue