2022-08-18 17:40:33 +00:00
|
|
|
#include <fspr.h>
|
|
|
|
#include <fspr_random.h>
|
|
|
|
#include <fspr_pools.h>
|
2006-12-19 19:58:23 +00:00
|
|
|
#include "sha2.h"
|
|
|
|
|
2022-08-18 17:40:33 +00:00
|
|
|
static void sha256_init(fspr_crypto_hash_t *h)
|
2006-12-19 19:58:23 +00:00
|
|
|
{
|
2022-08-18 17:40:33 +00:00
|
|
|
fspr__SHA256_Init(h->data);
|
2006-12-19 19:58:23 +00:00
|
|
|
}
|
|
|
|
|
2022-08-18 17:40:33 +00:00
|
|
|
static void sha256_add(fspr_crypto_hash_t *h,const void *data,
|
|
|
|
fspr_size_t bytes)
|
2006-12-19 19:58:23 +00:00
|
|
|
{
|
2022-08-18 17:40:33 +00:00
|
|
|
fspr__SHA256_Update(h->data,data,bytes);
|
2006-12-19 19:58:23 +00:00
|
|
|
}
|
|
|
|
|
2022-08-18 17:40:33 +00:00
|
|
|
static void sha256_finish(fspr_crypto_hash_t *h,unsigned char *result)
|
2006-12-19 19:58:23 +00:00
|
|
|
{
|
2022-08-18 17:40:33 +00:00
|
|
|
fspr__SHA256_Final(result,h->data);
|
2006-12-19 19:58:23 +00:00
|
|
|
}
|
|
|
|
|
2022-08-18 17:40:33 +00:00
|
|
|
APR_DECLARE(fspr_crypto_hash_t *) fspr_crypto_sha256_new(fspr_pool_t *p)
|
2006-12-19 19:58:23 +00:00
|
|
|
{
|
2022-08-18 17:40:33 +00:00
|
|
|
fspr_crypto_hash_t *h=fspr_palloc(p,sizeof *h);
|
2006-12-19 19:58:23 +00:00
|
|
|
|
2022-08-18 17:40:33 +00:00
|
|
|
h->data=fspr_palloc(p,sizeof(SHA256_CTX));
|
2006-12-19 19:58:23 +00:00
|
|
|
h->init=sha256_init;
|
|
|
|
h->add=sha256_add;
|
|
|
|
h->finish=sha256_finish;
|
|
|
|
h->size=256/8;
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|