switch to EVP_MD_CTX_create() and thus make smaller
This commit is contained in:
@@ -31,6 +31,8 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define HC_DEPRECATED_CRYPTO
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "otp_locl.h"
|
#include "otp_locl.h"
|
||||||
@@ -83,13 +85,15 @@ otp_md_init (OtpKey key,
|
|||||||
const char *seed,
|
const char *seed,
|
||||||
const EVP_MD *md,
|
const EVP_MD *md,
|
||||||
int le,
|
int le,
|
||||||
EVP_MD_CTX *arg,
|
|
||||||
unsigned char *res,
|
unsigned char *res,
|
||||||
size_t ressz)
|
size_t ressz)
|
||||||
{
|
{
|
||||||
|
EVP_MD_CTX *ctx;
|
||||||
char *p;
|
char *p;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
ctx = EVP_MD_CTX_create();
|
||||||
|
|
||||||
len = strlen(pwd) + strlen(seed);
|
len = strlen(pwd) + strlen(seed);
|
||||||
p = malloc (len + 1);
|
p = malloc (len + 1);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
@@ -98,9 +102,11 @@ otp_md_init (OtpKey key,
|
|||||||
strlwr (p);
|
strlwr (p);
|
||||||
strlcat (p, pwd, len + 1);
|
strlcat (p, pwd, len + 1);
|
||||||
|
|
||||||
EVP_DigestInit_ex(arg, md, NULL);
|
EVP_DigestInit_ex(ctx, md, NULL);
|
||||||
EVP_DigestUpdate(arg, p, len);
|
EVP_DigestUpdate(ctx, p, len);
|
||||||
EVP_DigestFinal_ex(arg, res, NULL);
|
EVP_DigestFinal_ex(ctx, res, NULL);
|
||||||
|
|
||||||
|
EVP_MD_CTX_destroy(ctx);
|
||||||
|
|
||||||
if (le)
|
if (le)
|
||||||
little_endian(res, ressz);
|
little_endian(res, ressz);
|
||||||
@@ -114,13 +120,18 @@ static int
|
|||||||
otp_md_next (OtpKey key,
|
otp_md_next (OtpKey key,
|
||||||
const EVP_MD *md,
|
const EVP_MD *md,
|
||||||
int le,
|
int le,
|
||||||
EVP_MD_CTX *arg,
|
|
||||||
unsigned char *res,
|
unsigned char *res,
|
||||||
size_t ressz)
|
size_t ressz)
|
||||||
{
|
{
|
||||||
EVP_DigestInit_ex(arg, md, NULL);
|
EVP_MD_CTX *ctx;
|
||||||
EVP_DigestUpdate(arg, key, OTPKEYSIZE);
|
|
||||||
EVP_DigestFinal_ex(arg, res, NULL);
|
ctx = EVP_MD_CTX_create();
|
||||||
|
|
||||||
|
EVP_DigestInit_ex(ctx, md, NULL);
|
||||||
|
EVP_DigestUpdate(ctx, key, OTPKEYSIZE);
|
||||||
|
EVP_DigestFinal_ex(ctx, res, NULL);
|
||||||
|
|
||||||
|
EVP_MD_CTX_destroy(ctx);
|
||||||
|
|
||||||
if (le)
|
if (le)
|
||||||
little_endian(res, ressz);
|
little_endian(res, ressz);
|
||||||
@@ -134,13 +145,17 @@ otp_md_hash (const char *data,
|
|||||||
size_t len,
|
size_t len,
|
||||||
const EVP_MD *md,
|
const EVP_MD *md,
|
||||||
int le,
|
int le,
|
||||||
EVP_MD_CTX *arg,
|
|
||||||
unsigned char *res,
|
unsigned char *res,
|
||||||
size_t ressz)
|
size_t ressz)
|
||||||
{
|
{
|
||||||
EVP_DigestInit_ex(arg, md, NULL);
|
EVP_MD_CTX *ctx;
|
||||||
EVP_DigestUpdate(arg, data, len);
|
ctx = EVP_MD_CTX_create();
|
||||||
EVP_DigestFinal_ex(arg, res, NULL);
|
|
||||||
|
EVP_DigestInit_ex(ctx, md, NULL);
|
||||||
|
EVP_DigestUpdate(ctx, data, len);
|
||||||
|
EVP_DigestFinal_ex(ctx, res, NULL);
|
||||||
|
|
||||||
|
EVP_MD_CTX_destroy(ctx);
|
||||||
|
|
||||||
if (le)
|
if (le)
|
||||||
little_endian(res, ressz);
|
little_endian(res, ressz);
|
||||||
@@ -152,11 +167,7 @@ int
|
|||||||
otp_md4_init (OtpKey key, const char *pwd, const char *seed)
|
otp_md4_init (OtpKey key, const char *pwd, const char *seed)
|
||||||
{
|
{
|
||||||
unsigned char res[16];
|
unsigned char res[16];
|
||||||
EVP_MD_CTX ctx;
|
return otp_md_init (key, pwd, seed, EVP_md4(), 0, res, sizeof(res));
|
||||||
|
|
||||||
EVP_MD_CTX_init(&ctx);
|
|
||||||
|
|
||||||
return otp_md_init (key, pwd, seed, EVP_md4(), 0, &ctx, res, sizeof(res));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -164,22 +175,14 @@ otp_md4_hash (const char *data,
|
|||||||
size_t len,
|
size_t len,
|
||||||
unsigned char *res)
|
unsigned char *res)
|
||||||
{
|
{
|
||||||
EVP_MD_CTX ctx;
|
return otp_md_hash (data, len, EVP_md4(), 0, res, 16);
|
||||||
|
|
||||||
EVP_MD_CTX_init(&ctx);
|
|
||||||
|
|
||||||
return otp_md_hash (data, len, EVP_md4(), 0, &ctx, res, 16);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
otp_md4_next (OtpKey key)
|
otp_md4_next (OtpKey key)
|
||||||
{
|
{
|
||||||
unsigned char res[16];
|
unsigned char res[16];
|
||||||
EVP_MD_CTX ctx;
|
return otp_md_next (key, EVP_md4(), 0, res, sizeof(res));
|
||||||
|
|
||||||
EVP_MD_CTX_init(&ctx);
|
|
||||||
|
|
||||||
return otp_md_next (key, EVP_md4(), 0, &ctx, res, sizeof(res));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -187,11 +190,7 @@ int
|
|||||||
otp_md5_init (OtpKey key, const char *pwd, const char *seed)
|
otp_md5_init (OtpKey key, const char *pwd, const char *seed)
|
||||||
{
|
{
|
||||||
unsigned char res[16];
|
unsigned char res[16];
|
||||||
EVP_MD_CTX ctx;
|
return otp_md_init (key, pwd, seed, EVP_md5(), 0, res, sizeof(res));
|
||||||
|
|
||||||
EVP_MD_CTX_init(&ctx);
|
|
||||||
|
|
||||||
return otp_md_init (key, pwd, seed, EVP_md5(), 0, &ctx, res, sizeof(res));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -199,33 +198,21 @@ otp_md5_hash (const char *data,
|
|||||||
size_t len,
|
size_t len,
|
||||||
unsigned char *res)
|
unsigned char *res)
|
||||||
{
|
{
|
||||||
EVP_MD_CTX ctx;
|
return otp_md_hash (data, len, EVP_md5(), 0, res, 16);
|
||||||
|
|
||||||
EVP_MD_CTX_init(&ctx);
|
|
||||||
|
|
||||||
return otp_md_hash (data, len, EVP_md5(), 0, &ctx, res, 16);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
otp_md5_next (OtpKey key)
|
otp_md5_next (OtpKey key)
|
||||||
{
|
{
|
||||||
unsigned char res[16];
|
unsigned char res[16];
|
||||||
EVP_MD_CTX ctx;
|
return otp_md_next (key, EVP_md5(), 0, res, sizeof(res));
|
||||||
|
|
||||||
EVP_MD_CTX_init(&ctx);
|
|
||||||
|
|
||||||
return otp_md_next (key, EVP_md5(), 0, &ctx, res, sizeof(res));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
otp_sha_init (OtpKey key, const char *pwd, const char *seed)
|
otp_sha_init (OtpKey key, const char *pwd, const char *seed)
|
||||||
{
|
{
|
||||||
unsigned char res[20];
|
unsigned char res[20];
|
||||||
EVP_MD_CTX ctx;
|
return otp_md_init (key, pwd, seed, EVP_sha1(), 1, res, sizeof(res));
|
||||||
|
|
||||||
EVP_MD_CTX_init(&ctx);
|
|
||||||
|
|
||||||
return otp_md_init (key, pwd, seed, EVP_sha1(), 1, &ctx, res, sizeof(res));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -233,20 +220,12 @@ otp_sha_hash (const char *data,
|
|||||||
size_t len,
|
size_t len,
|
||||||
unsigned char *res)
|
unsigned char *res)
|
||||||
{
|
{
|
||||||
EVP_MD_CTX ctx;
|
return otp_md_hash (data, len, EVP_sha1(), 1, res, 20);
|
||||||
|
|
||||||
EVP_MD_CTX_init(&ctx);
|
|
||||||
|
|
||||||
return otp_md_hash (data, len, EVP_sha1(), 1, &ctx, res, 20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
otp_sha_next (OtpKey key)
|
otp_sha_next (OtpKey key)
|
||||||
{
|
{
|
||||||
unsigned char res[20];
|
unsigned char res[20];
|
||||||
EVP_MD_CTX ctx;
|
return otp_md_next (key, EVP_sha1(), 1, res, sizeof(res));
|
||||||
|
|
||||||
EVP_MD_CTX_init(&ctx);
|
|
||||||
|
|
||||||
return otp_md_next (key, EVP_sha1(), 1, &ctx, res, sizeof(res));
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user