emile: API break, rename sha1 to hmac_sha1, introduce real sha1.
emile_binbuf_sha1() was actually doing HMAC version using the given key. This doesn't work when all you need is just the SHA1 of the input data. Then rename emile_binbuf_sha1() to emile_binbuf_hmac_sha1() and introduce a new version without key/keylen. This API was marked as BETA and no real users in the codebase, then it shouldn't cause us problems.
This commit is contained in:
parent
5b8315aeff
commit
d8caade348
|
@ -14,10 +14,16 @@ Eina_Bool _emile_cipher_init(void)
|
|||
}
|
||||
|
||||
EAPI Eina_Bool
|
||||
emile_binbuf_sha1(const char *key EINA_UNUSED,
|
||||
unsigned int key_len EINA_UNUSED,
|
||||
const Eina_Binbuf *data EINA_UNUSED,
|
||||
unsigned char digest[20] EINA_UNUSED)
|
||||
emile_binbuf_hmac_sha1(const char *key EINA_UNUSED,
|
||||
unsigned int key_len EINA_UNUSED,
|
||||
const Eina_Binbuf *data EINA_UNUSED,
|
||||
unsigned char digest[20] EINA_UNUSED)
|
||||
{
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
EAPI Eina_Bool
|
||||
emile_binbuf_sha1(const Eina_Binbuf * data, unsigned char digest[20])
|
||||
{
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
|
|
@ -102,7 +102,9 @@ typedef enum
|
|||
EMILE_WANT_WRITE = 3
|
||||
} Emile_Want_Type;
|
||||
|
||||
EAPI Eina_Bool emile_binbuf_sha1(const char *key, unsigned int key_len, const Eina_Binbuf * data, unsigned char digest[20]);
|
||||
EAPI Eina_Bool emile_binbuf_hmac_sha1(const char *key, unsigned int key_len, const Eina_Binbuf * data, unsigned char digest[20]);
|
||||
|
||||
EAPI Eina_Bool emile_binbuf_sha1(const Eina_Binbuf * data, unsigned char digest[20]);
|
||||
|
||||
|
||||
EAPI Emile_SSL *emile_cipher_server_listen(Emile_Cipher_Type t);
|
||||
|
|
|
@ -125,16 +125,53 @@ emile_hmac_sha1(const void *key,
|
|||
}
|
||||
|
||||
EAPI Eina_Bool
|
||||
emile_binbuf_sha1(const char *key,
|
||||
unsigned int key_len,
|
||||
const Eina_Binbuf *data,
|
||||
unsigned char digest[20])
|
||||
emile_binbuf_hmac_sha1(const char *key,
|
||||
unsigned int key_len,
|
||||
const Eina_Binbuf *data,
|
||||
unsigned char digest[20])
|
||||
{
|
||||
return emile_hmac_sha1(key, key_len,
|
||||
eina_binbuf_string_get(data), eina_binbuf_length_get(data),
|
||||
digest);
|
||||
}
|
||||
|
||||
static inline Eina_Bool
|
||||
emile_sha1(const void *data,
|
||||
size_t data_len,
|
||||
unsigned char *res)
|
||||
{
|
||||
size_t hlen = gcry_md_get_algo_dlen(GCRY_MD_SHA1);
|
||||
gcry_md_hd_t mdh;
|
||||
unsigned char *hash;
|
||||
gpg_error_t err;
|
||||
|
||||
err = gcry_md_open(&mdh, GCRY_MD_SHA1, 0);
|
||||
if (err != GPG_ERR_NO_ERROR)
|
||||
return EINA_FALSE;
|
||||
|
||||
gcry_md_write(mdh, data, data_len);
|
||||
|
||||
hash = gcry_md_read(mdh, GCRY_MD_SHA1);
|
||||
if (!hash)
|
||||
{
|
||||
gcry_md_close(mdh);
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
memcpy(res, hash, hlen);
|
||||
|
||||
gcry_md_close(mdh);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
EAPI Eina_Bool
|
||||
emile_binbuf_sha1(const Eina_Binbuf * data, unsigned char digest[20])
|
||||
{
|
||||
Eina_Slice slice = eina_binbuf_slice_get(data);
|
||||
return emile_sha1(data.mem, data.len, digest);
|
||||
}
|
||||
|
||||
EAPI Eina_Binbuf *
|
||||
emile_binbuf_cipher(Emile_Cipher_Algorithm algo,
|
||||
const Eina_Binbuf *data,
|
||||
|
|
|
@ -58,10 +58,10 @@ _emile_cipher_init(void)
|
|||
}
|
||||
|
||||
EAPI Eina_Bool
|
||||
emile_binbuf_sha1(const char *key,
|
||||
unsigned int key_len,
|
||||
const Eina_Binbuf *data,
|
||||
unsigned char digest[20])
|
||||
emile_binbuf_hmac_sha1(const char *key,
|
||||
unsigned int key_len,
|
||||
const Eina_Binbuf *data,
|
||||
unsigned char digest[20])
|
||||
{
|
||||
HMAC(EVP_sha1(),
|
||||
key, key_len,
|
||||
|
@ -70,6 +70,23 @@ emile_binbuf_sha1(const char *key,
|
|||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
EAPI Eina_Bool
|
||||
emile_binbuf_sha1(const Eina_Binbuf * data, unsigned char digest[20])
|
||||
{
|
||||
const EVP_MD *md = EVP_sha1();
|
||||
Eina_Slice slice = eina_binbuf_slice_get(data);
|
||||
EVP_MD_CTX ctx;
|
||||
|
||||
EVP_MD_CTX_init(&ctx);
|
||||
EVP_DigestInit_ex(&ctx, md, NULL);
|
||||
|
||||
EVP_DigestUpdate(&ctx, slice.mem, slice.len);
|
||||
EVP_DigestFinal_ex(&ctx, digest, NULL);
|
||||
|
||||
EVP_MD_CTX_cleanup(&ctx);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
EAPI Eina_Binbuf *
|
||||
emile_binbuf_cipher(Emile_Cipher_Algorithm algo,
|
||||
const Eina_Binbuf *data,
|
||||
|
|
|
@ -154,14 +154,14 @@ emile_pbkdf2_sha1(const char *key, unsigned int key_len, const unsigned char *sa
|
|||
memcpy(buf, salt, salt_len);
|
||||
memcpy(buf + salt_len, tab, 4);
|
||||
|
||||
if (!emile_binbuf_sha1(key, key_len, step1, digest))
|
||||
if (!emile_binbuf_hmac_sha1(key, key_len, step1, digest))
|
||||
return EINA_FALSE;
|
||||
|
||||
memcpy(p, digest, tmp_len);
|
||||
|
||||
for (j = 1; j < iter; j++)
|
||||
{
|
||||
if (!emile_binbuf_sha1(key, key_len, step2, digest))
|
||||
if (!emile_binbuf_hmac_sha1(key, key_len, step2, digest))
|
||||
return EINA_FALSE;
|
||||
for (k = 0; k < tmp_len; k++)
|
||||
p[k] ^= digest[k];
|
||||
|
|
Loading…
Reference in New Issue