infra: move crypto stuff from sy_old/ to mars_generic

This commit is contained in:
Thomas Schoebel-Theuer 2012-08-01 12:01:13 +02:00 committed by Thomas Schoebel-Theuer
parent 8dccc70d00
commit dd8c0df8e2
4 changed files with 61 additions and 54 deletions

8
mars.h
View File

@ -339,6 +339,14 @@ static inline void unuse_fake_mm(void) {}
/////////////////////////////////////////////////////////////////////////
/* Crypto stuff
*/
extern int mars_digest_size;
extern void mars_digest(unsigned char *digest, void *data, int len);
/////////////////////////////////////////////////////////////////////////
// init
extern int init_mars(void);

View File

@ -93,6 +93,34 @@ const struct meta mars_timespec_meta[] = {
EXPORT_SYMBOL_GPL(mars_timespec_meta);
//////////////////////////////////////////////////////////////
// crypto stuff
#include <linux/crypto.h>
struct crypto_hash *mars_tfm = NULL;
int mars_digest_size = 0;
EXPORT_SYMBOL_GPL(mars_digest_size);
void mars_digest(unsigned char *digest, void *data, int len)
{
struct hash_desc desc = {
.tfm = mars_tfm,
.flags = 0,
};
struct scatterlist sg;
memset(digest, 0, mars_digest_size);
crypto_hash_init(&desc);
sg_init_table(&sg, 1);
sg_set_buf(&sg, data, len);
crypto_hash_update(&desc, &sg, sg.length);
crypto_hash_final(&desc, digest);
}
EXPORT_SYMBOL_GPL(mars_digest);
/////////////////////////////////////////////////////////////////////
// tracing
@ -250,13 +278,38 @@ int __init init_mars(void)
}
}
#endif
mars_tfm = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC);
if (!mars_tfm) {
MARS_ERR("cannot alloc crypto hash\n");
return -ENOMEM;
}
if (IS_ERR(mars_tfm)) {
MARS_ERR("alloc crypto hash failed, status = %d\n", (int)PTR_ERR(mars_tfm));
return PTR_ERR(mars_tfm);
}
#if 0
if (crypto_tfm_alg_type(crypto_hash_tfm(mars_tfm)) != CRYPTO_ALG_TYPE_DIGEST) {
MARS_ERR("bad crypto hash type\n");
return -EINVAL;
}
#endif
mars_digest_size = crypto_hash_digestsize(mars_tfm);
MARS_INF("digest_size = %d\n", mars_digest_size);
return 0;
}
void __exit exit_mars(void)
{
MARS_INF("exit_mars()\n");
put_fake();
if (mars_tfm) {
crypto_free_hash(mars_tfm);
}
#ifdef MARS_TRACING
if (mars_log_file) {
filp_close(mars_log_file, NULL);

View File

@ -132,11 +132,6 @@ extern struct mars_global *mars_global;
extern int mars_power_button(struct mars_brick *brick, bool val, bool force_off);
extern int mars_power_button_recursive(struct mars_brick *brick, bool val, bool force_off, int timeout);
/* Crypto stuff
*/
extern int mars_digest_size;
extern void mars_digest(unsigned char *digest, void *data, int len);
/////////////////////////////////////////////////////////////////////////
// quirk

View File

@ -260,34 +260,6 @@ EXPORT_SYMBOL_GPL(mars_remaining_space);
//////////////////////////////////////////////////////////////
// crypto stuff
#include <linux/crypto.h>
struct crypto_hash *mars_tfm = NULL;
int mars_digest_size = 0;
EXPORT_SYMBOL_GPL(mars_digest_size);
void mars_digest(unsigned char *digest, void *data, int len)
{
struct hash_desc desc = {
.tfm = mars_tfm,
.flags = 0,
};
struct scatterlist sg;
memset(digest, 0, mars_digest_size);
crypto_hash_init(&desc);
sg_init_table(&sg, 1);
sg_set_buf(&sg, data, len);
crypto_hash_update(&desc, &sg, sg.length);
crypto_hash_final(&desc, digest);
}
EXPORT_SYMBOL_GPL(mars_digest);
//////////////////////////////////////////////////////////////
// infrastructure
struct mars_global *mars_global = NULL;
@ -1484,33 +1456,12 @@ int __init init_sy(void)
_mars_trigger = __mars_trigger;
mars_tfm = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC);
if (!mars_tfm) {
MARS_ERR("cannot alloc crypto hash\n");
return -ENOMEM;
}
if (IS_ERR(mars_tfm)) {
MARS_ERR("alloc crypto hash failed, status = %d\n", (int)PTR_ERR(mars_tfm));
return PTR_ERR(mars_tfm);
}
#if 0
if (crypto_tfm_alg_type(crypto_hash_tfm(mars_tfm)) != CRYPTO_ALG_TYPE_DIGEST) {
MARS_ERR("bad crypto hash type\n");
return -EINVAL;
}
#endif
mars_digest_size = crypto_hash_digestsize(mars_tfm);
MARS_INF("digest_size = %d\n", mars_digest_size);
return 0;
}
void __exit exit_sy(void)
{
MARS_INF("exit_sy()\n");
if (mars_tfm) {
crypto_free_hash(mars_tfm);
}
}
#ifndef CONFIG_MARS_HAVE_BIGMODULE