mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-14 04:10:06 +01:00
* Remove hash/hmac restart from crypto backend and make it part of hash/hmac final.
Some backend implementation did reset context by default, so this should create backend api consistent. git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@578 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
2011-07-25 Milan Broz <mbroz@redhat.com>
|
||||||
|
* Remove hash/hmac restart from crypto backend and make it part of hash/hmac final.
|
||||||
|
|
||||||
2011-07-19 Milan Broz <mbroz@redhat.com>
|
2011-07-19 Milan Broz <mbroz@redhat.com>
|
||||||
* Revert default initialisation of volume key in crypt_init_by_name().
|
* Revert default initialisation of volume key in crypt_init_by_name().
|
||||||
* Do not allow key retrieval while suspended (key could be wiped).
|
* Do not allow key retrieval while suspended (key could be wiped).
|
||||||
|
|||||||
@@ -54,8 +54,6 @@ static int hash(const char *hash_name, size_t key_size, char *key,
|
|||||||
|
|
||||||
key += len;
|
key += len;
|
||||||
key_size -= len;
|
key_size -= len;
|
||||||
if (key_size && crypt_hash_restart(md))
|
|
||||||
r = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
crypt_hash_destroy(md);
|
crypt_hash_destroy(md);
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ uint32_t crypt_backend_flags(void);
|
|||||||
/* HASH */
|
/* HASH */
|
||||||
int crypt_hash_size(const char *name);
|
int crypt_hash_size(const char *name);
|
||||||
int crypt_hash_init(struct crypt_hash **ctx, const char *name);
|
int crypt_hash_init(struct crypt_hash **ctx, const char *name);
|
||||||
int crypt_hash_restart(struct crypt_hash *ctx);
|
|
||||||
int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length);
|
int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length);
|
||||||
int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length);
|
int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length);
|
||||||
int crypt_hash_destroy(struct crypt_hash *ctx);
|
int crypt_hash_destroy(struct crypt_hash *ctx);
|
||||||
@@ -25,7 +24,6 @@ int crypt_hash_destroy(struct crypt_hash *ctx);
|
|||||||
int crypt_hmac_size(const char *name);
|
int crypt_hmac_size(const char *name);
|
||||||
int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
||||||
const void *buffer, size_t length);
|
const void *buffer, size_t length);
|
||||||
int crypt_hmac_restart(struct crypt_hmac *ctx);
|
|
||||||
int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length);
|
int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length);
|
||||||
int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length);
|
int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length);
|
||||||
int crypt_hmac_destroy(struct crypt_hmac *ctx);
|
int crypt_hmac_destroy(struct crypt_hmac *ctx);
|
||||||
|
|||||||
@@ -117,10 +117,9 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_hash_restart(struct crypt_hash *ctx)
|
static void crypt_hash_restart(struct crypt_hash *ctx)
|
||||||
{
|
{
|
||||||
gcry_md_reset(ctx->hd);
|
gcry_md_reset(ctx->hd);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length)
|
int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length)
|
||||||
@@ -140,6 +139,8 @@ int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length)
|
|||||||
if (!hash)
|
if (!hash)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
crypt_hash_restart(ctx);
|
||||||
|
|
||||||
memcpy(buffer, hash, length);
|
memcpy(buffer, hash, length);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -191,10 +192,9 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_hmac_restart(struct crypt_hmac *ctx)
|
static void crypt_hmac_restart(struct crypt_hmac *ctx)
|
||||||
{
|
{
|
||||||
gcry_md_reset(ctx->hd);
|
gcry_md_reset(ctx->hd);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length)
|
int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length)
|
||||||
@@ -214,6 +214,8 @@ int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length)
|
|||||||
if (!hash)
|
if (!hash)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
crypt_hmac_restart(ctx);
|
||||||
|
|
||||||
memcpy(buffer, hash, length);
|
memcpy(buffer, hash, length);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,11 +176,6 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_hash_restart(struct crypt_hash *ctx)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length)
|
int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length)
|
||||||
{
|
{
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
@@ -261,11 +256,6 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_hmac_restart(struct crypt_hmac *ctx)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length)
|
int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length)
|
||||||
{
|
{
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
|
|||||||
@@ -159,10 +159,9 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_hash_restart(struct crypt_hash *ctx)
|
static void crypt_hash_restart(struct crypt_hash *ctx)
|
||||||
{
|
{
|
||||||
ctx->hash->init(&ctx->nettle_ctx);
|
ctx->hash->init(&ctx->nettle_ctx);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length)
|
int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length)
|
||||||
@@ -177,6 +176,7 @@ int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
ctx->hash->digest(&ctx->nettle_ctx, length, (uint8_t *)buffer);
|
ctx->hash->digest(&ctx->nettle_ctx, length, (uint8_t *)buffer);
|
||||||
|
crypt_hash_restart(ctx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ bad:
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_hmac_restart(struct crypt_hmac *ctx)
|
static void crypt_hmac_restart(struct crypt_hmac *ctx)
|
||||||
{
|
{
|
||||||
ctx->hash->hmac_set_key(&ctx->nettle_ctx, ctx->key_length, ctx->key);
|
ctx->hash->hmac_set_key(&ctx->nettle_ctx, ctx->key_length, ctx->key);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -243,6 +243,7 @@ int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
ctx->hash->hmac_digest(&ctx->nettle_ctx, length, (uint8_t *)buffer);
|
ctx->hash->hmac_digest(&ctx->nettle_ctx, length, (uint8_t *)buffer);
|
||||||
|
crypt_hmac_restart(ctx);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_hash_restart(struct crypt_hash *ctx)
|
static int crypt_hash_restart(struct crypt_hash *ctx)
|
||||||
{
|
{
|
||||||
if (PK11_DigestBegin(ctx->md) != SECSuccess)
|
if (PK11_DigestBegin(ctx->md) != SECSuccess)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -154,6 +154,9 @@ int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length)
|
|||||||
if (tmp_len < length)
|
if (tmp_len < length)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (crypt_hash_restart(ctx))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +223,7 @@ bad:
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_hmac_restart(struct crypt_hmac *ctx)
|
static int crypt_hmac_restart(struct crypt_hmac *ctx)
|
||||||
{
|
{
|
||||||
if (PK11_DigestBegin(ctx->md) != SECSuccess)
|
if (PK11_DigestBegin(ctx->md) != SECSuccess)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -253,6 +256,9 @@ int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length)
|
|||||||
if (tmp_len < length)
|
if (tmp_len < length)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (crypt_hmac_restart(ctx))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ int crypt_hash_init(struct crypt_hash **ctx, const char *name)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_hash_restart(struct crypt_hash *ctx)
|
static int crypt_hash_restart(struct crypt_hash *ctx)
|
||||||
{
|
{
|
||||||
if (EVP_DigestInit(&ctx->md, ctx->hash_id) != 1)
|
if (EVP_DigestInit(&ctx->md, ctx->hash_id) != 1)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -131,6 +131,9 @@ int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length)
|
|||||||
if (tmp_len < length)
|
if (tmp_len < length)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
if (crypt_hash_restart(ctx))
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,10 +174,9 @@ int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_hmac_restart(struct crypt_hmac *ctx)
|
static void crypt_hmac_restart(struct crypt_hmac *ctx)
|
||||||
{
|
{
|
||||||
HMAC_Init_ex(&ctx->md, NULL, 0, ctx->hash_id, NULL);
|
HMAC_Init_ex(&ctx->md, NULL, 0, ctx->hash_id, NULL);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length)
|
int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length)
|
||||||
@@ -199,6 +201,8 @@ int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length)
|
|||||||
if (tmp_len < length)
|
if (tmp_len < length)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
crypt_hmac_restart(ctx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -167,9 +167,6 @@ static int pkcs5_pbkdf2(const char *hash,
|
|||||||
memset(T, 0, hLen);
|
memset(T, 0, hLen);
|
||||||
|
|
||||||
for (u = 1; u <= c ; u++) {
|
for (u = 1; u <= c ; u++) {
|
||||||
if (crypt_hmac_restart(hmac))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (u == 1) {
|
if (u == 1) {
|
||||||
memcpy(tmp, S, Slen);
|
memcpy(tmp, S, Slen);
|
||||||
tmp[Slen + 0] = (i & 0xff000000) >> 24;
|
tmp[Slen + 0] = (i & 0xff000000) >> 24;
|
||||||
|
|||||||
Reference in New Issue
Block a user