Index: linux-2.6.7/crypto/api.c =================================================================== --- linux-2.6.7.orig/crypto/api.c +++ linux-2.6.7/crypto/api.c @@ -43,14 +43,16 @@ down_read(&crypto_alg_sem); list_for_each_entry(q, &crypto_alg_list, cra_list) { - if (!(strcmp(q->cra_name, name))) { - if (crypto_alg_get(q)) - alg = q; - break; - } + if (!(strcmp(q->cra_name, name)) + && (!alg || alg->cra_preference < q->cra_preference)) + alg = q; } + if (alg && !crypto_alg_get(alg)) + alg = NULL; + up_read(&crypto_alg_sem); + return alg; } @@ -163,20 +165,11 @@ int crypto_register_alg(struct crypto_alg *alg) { int ret = 0; - struct crypto_alg *q; down_write(&crypto_alg_sem); - - list_for_each_entry(q, &crypto_alg_list, cra_list) { - if (!(strcmp(q->cra_name, alg->cra_name))) { - ret = -EEXIST; - goto out; - } - } - list_add_tail(&alg->cra_list, &crypto_alg_list); -out: up_write(&crypto_alg_sem); + return ret; } Index: linux-2.6.7/include/linux/crypto.h =================================================================== --- linux-2.6.7.orig/include/linux/crypto.h +++ linux-2.6.7/include/linux/crypto.h @@ -56,6 +57,10 @@ #define CRYPTO_UNSPEC 0 #define CRYPTO_MAX_ALG_NAME 64 +#define CRYPTO_PREF_GENERIC 0 +#define CRYPTO_PREF_OPTIMIZED 10 +#define CRYPTO_PREF_HARDAWRE 20 + struct scatterlist; /* @@ -99,6 +118,7 @@ unsigned int cra_blocksize; unsigned int cra_ctxsize; const char cra_name[CRYPTO_MAX_ALG_NAME]; + unsigned int cra_preference; union { struct cipher_alg cipher;