/* Don't assume ctx->md_data was cleaned in EVP_Digest_Final,
* because sometimes only copies of the context are ever finalised.
*/
+ if(ctx->digest && ctx->digest->cleanup)
+ ctx->digest->cleanup(ctx);
if(ctx->digest && ctx->digest->ctx_size && ctx->md_data)
{
memset(ctx->md_data,0,ctx->digest->ctx_size);
int (*update)(EVP_MD_CTX *ctx,const void *data,unsigned long count);
int (*final)(EVP_MD_CTX *ctx,unsigned char *md);
int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from);
+ int (*cleanup)(EVP_MD_CTX *ctx);
/* FIXME: prototype these some day */
int (*sign)();
update,
final,
NULL,
+ NULL,
EVP_PKEY_DSA_method,
SHA_CBLOCK,
sizeof(EVP_MD *)+sizeof(SHA_CTX),
update,
final,
NULL,
+ NULL,
EVP_PKEY_DSA_method,
SHA_CBLOCK,
sizeof(EVP_MD *)+sizeof(SHA_CTX),
update,
final,
NULL,
+ NULL,
EVP_PKEY_RSA_method,
MD2_BLOCK,
sizeof(EVP_MD *)+sizeof(MD2_CTX),
update,
final,
NULL,
+ NULL,
EVP_PKEY_RSA_method,
MD4_CBLOCK,
sizeof(EVP_MD *)+sizeof(MD4_CTX),
update,
final,
NULL,
+ NULL,
EVP_PKEY_RSA_method,
MD5_CBLOCK,
sizeof(EVP_MD *)+sizeof(MD5_CTX),
update,
final,
NULL,
+ NULL,
EVP_PKEY_RSA_ASN1_OCTET_STRING_method,
MDC2_BLOCK,
sizeof(EVP_MD *)+sizeof(MDC2_CTX),
update,
final,
NULL,
+ NULL,
EVP_PKEY_NULL_method,
0,
sizeof(EVP_MD *),
update,
final,
NULL,
+ NULL,
EVP_PKEY_RSA_method,
RIPEMD160_CBLOCK,
sizeof(EVP_MD *)+sizeof(RIPEMD160_CTX),
update,
final,
NULL,
+ NULL,
EVP_PKEY_RSA_method,
SHA_CBLOCK,
sizeof(EVP_MD *)+sizeof(SHA_CTX),
update,
final,
NULL,
+ NULL,
EVP_PKEY_RSA_method,
SHA_CBLOCK,
sizeof(EVP_MD *)+sizeof(SHA_CTX),
return 1;
}
+static int dev_crypto_cleanup_digest(MD_DATA *md_data)
+ {
+ if (ioctl(fd,CIOCFSESSION,&md_data->sess.ses) == -1)
+ {
+ err("CIOCFSESSION failed");
+ return 0;
+ }
+
+ return 1;
+ }
+
/* FIXME: if device can do chained MACs, then don't accumulate */
/* FIXME: move accumulation to the framework */
static int dev_crypto_md5_init(EVP_MD_CTX *ctx)
return 0;
}
}
- printf("done\n");
+ // printf("done\n");
return 1;
}
if(ctx->flags&EVP_MD_CTX_FLAG_ONESHOT)
{
memcpy(md,md_data->md,MD5_DIGEST_LENGTH);
- return 1;
+ ret=1;
+ }
+ else
+ {
+ ret=do_digest(md_data->sess.ses,md,md_data->data,md_data->len);
+ OPENSSL_free(md_data->data);
+ md_data->data=NULL;
+ md_data->len=0;
}
-
- ret=do_digest(md_data->sess.ses,md,md_data->data,md_data->len);
- OPENSSL_free(md_data->data);
- md_data->data=NULL;
- md_data->len=0;
return ret;
}
return 1;
}
+static int dev_crypto_md5_cleanup(EVP_MD_CTX *ctx)
+ {
+ return dev_crypto_cleanup_digest(ctx->md_data);
+ }
+
static const EVP_MD md5_md=
{
NID_md5,
dev_crypto_md5_update,
dev_crypto_md5_final,
dev_crypto_md5_copy,
+ dev_crypto_md5_cleanup,
EVP_PKEY_RSA_method,
MD5_CBLOCK,
sizeof(MD_DATA),