+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>
* Revert default initialisation of volume key in crypt_init_by_name().
* Do not allow key retrieval while suspended (key could be wiped).
key += len;
key_size -= len;
- if (key_size && crypt_hash_restart(md))
- r = 1;
}
crypt_hash_destroy(md);
/* HASH */
int crypt_hash_size(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_final(struct crypt_hash *ctx, char *buffer, size_t length);
int crypt_hash_destroy(struct crypt_hash *ctx);
int crypt_hmac_size(const char *name);
int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
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_final(struct crypt_hmac *ctx, char *buffer, size_t length);
int crypt_hmac_destroy(struct crypt_hmac *ctx);
return 0;
}
-int crypt_hash_restart(struct crypt_hash *ctx)
+static void crypt_hash_restart(struct crypt_hash *ctx)
{
gcry_md_reset(ctx->hd);
- return 0;
}
int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length)
if (!hash)
return -EINVAL;
+ crypt_hash_restart(ctx);
+
memcpy(buffer, hash, length);
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);
- return 0;
}
int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length)
if (!hash)
return -EINVAL;
+ crypt_hmac_restart(ctx);
+
memcpy(buffer, hash, length);
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)
{
ssize_t r;
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)
{
ssize_t r;
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);
- return 0;
}
int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length)
return -EINVAL;
ctx->hash->digest(&ctx->nettle_ctx, length, (uint8_t *)buffer);
+ crypt_hash_restart(ctx);
return 0;
}
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);
return 0;
return -EINVAL;
ctx->hash->hmac_digest(&ctx->nettle_ctx, length, (uint8_t *)buffer);
+ crypt_hmac_restart(ctx);
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)
return -EINVAL;
if (tmp_len < length)
return -EINVAL;
+ if (crypt_hash_restart(ctx))
+ return -EINVAL;
+
return 0;
}
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)
return -EINVAL;
if (tmp_len < length)
return -EINVAL;
+ if (crypt_hmac_restart(ctx))
+ return -EINVAL;
+
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)
return -EINVAL;
if (tmp_len < length)
return -EINVAL;
+ if (crypt_hash_restart(ctx))
+ return -EINVAL;
+
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);
- return 0;
}
int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length)
if (tmp_len < length)
return -EINVAL;
+ crypt_hmac_restart(ctx);
+
return 0;
}
memset(T, 0, hLen);
for (u = 1; u <= c ; u++) {
- if (crypt_hmac_restart(hmac))
- goto out;
-
if (u == 1) {
memcpy(tmp, S, Slen);
tmp[Slen + 0] = (i & 0xff000000) >> 24;