added libtomcrypt-1.05
This commit is contained in:
committed by
Steffen Jaeckel
parent
9da48eb84b
commit
9264e34ffb
@@ -301,6 +301,9 @@ const char *crypt_build_settings =
|
||||
#endif
|
||||
#if defined(LTC_NO_TABLES)
|
||||
" LTC_NO_TABLES "
|
||||
#endif
|
||||
#if defined(LTC_PTHREAD)
|
||||
" LTC_PTHREAD "
|
||||
#endif
|
||||
"\n"
|
||||
"\n\n\n"
|
||||
|
||||
@@ -19,6 +19,8 @@ struct ltc_cipher_descriptor cipher_descriptor[TAB_SIZE] = {
|
||||
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
LTC_MUTEX_GLOBAL(ltc_cipher_mutex);
|
||||
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
|
||||
@@ -22,9 +22,12 @@
|
||||
*/
|
||||
int cipher_is_valid(int idx)
|
||||
{
|
||||
LTC_MUTEX_LOCK(<c_cipher_mutex);
|
||||
if (idx < 0 || idx >= TAB_SIZE || cipher_descriptor[idx].name == NULL) {
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return CRYPT_INVALID_CIPHER;
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,11 +24,14 @@ int find_cipher(const char *name)
|
||||
{
|
||||
int x;
|
||||
LTC_ARGCHK(name != NULL);
|
||||
LTC_MUTEX_LOCK(<c_cipher_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (cipher_descriptor[x].name != NULL && !strcmp(cipher_descriptor[x].name, name)) {
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,14 +31,17 @@ int find_cipher_any(const char *name, int blocklen, int keylen)
|
||||
x = find_cipher(name);
|
||||
if (x != -1) return x;
|
||||
|
||||
LTC_MUTEX_LOCK(<c_cipher_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (cipher_descriptor[x].name == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (blocklen <= (int)cipher_descriptor[x].block_length && keylen <= (int)cipher_descriptor[x].max_key_length) {
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,15 @@
|
||||
int find_cipher_id(unsigned char ID)
|
||||
{
|
||||
int x;
|
||||
LTC_MUTEX_LOCK(<c_cipher_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (cipher_descriptor[x].ID == ID) {
|
||||
return (cipher_descriptor[x].name == NULL) ? -1 : x;
|
||||
x = (cipher_descriptor[x].name == NULL) ? -1 : x;
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,11 +24,14 @@ int find_hash(const char *name)
|
||||
{
|
||||
int x;
|
||||
LTC_ARGCHK(name != NULL);
|
||||
LTC_MUTEX_LOCK(<c_hash_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (hash_descriptor[x].name != NULL && strcmp(hash_descriptor[x].name, name) == 0) {
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
x = find_hash(name);
|
||||
if (x != -1) return x;
|
||||
|
||||
LTC_MUTEX_LOCK(<c_hash_mutex);
|
||||
y = MAXBLOCKSIZE+1;
|
||||
z = -1;
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
@@ -39,6 +40,7 @@
|
||||
y = hash_descriptor[x].hashsize;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return z;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,15 @@
|
||||
int find_hash_id(unsigned char ID)
|
||||
{
|
||||
int x;
|
||||
LTC_MUTEX_LOCK(<c_hash_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (hash_descriptor[x].ID == ID) {
|
||||
return (hash_descriptor[x].name == NULL) ? -1 : x;
|
||||
}
|
||||
if (hash_descriptor[x].ID == ID) {
|
||||
x = (hash_descriptor[x].name == NULL) ? -1 : x;
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,11 +24,14 @@ int find_prng(const char *name)
|
||||
{
|
||||
int x;
|
||||
LTC_ARGCHK(name != NULL);
|
||||
LTC_MUTEX_LOCK(<c_prng_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if ((prng_descriptor[x].name != NULL) && strcmp(prng_descriptor[x].name, name) == 0) {
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ struct ltc_hash_descriptor hash_descriptor[TAB_SIZE] = {
|
||||
{ NULL, 0, 0, 0, { 0 }, 0, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
LTC_MUTEX_GLOBAL(ltc_hash_mutex);
|
||||
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -22,9 +22,12 @@
|
||||
*/
|
||||
int hash_is_valid(int idx)
|
||||
{
|
||||
LTC_MUTEX_LOCK(<c_hash_mutex);
|
||||
if (idx < 0 || idx >= TAB_SIZE || hash_descriptor[idx].name == NULL) {
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return CRYPT_INVALID_HASH;
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ struct ltc_prng_descriptor prng_descriptor[TAB_SIZE] = {
|
||||
{ NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
LTC_MUTEX_GLOBAL(ltc_prng_mutex);
|
||||
|
||||
|
||||
/* $Source$ */
|
||||
/* $Revision$ */
|
||||
/* $Date$ */
|
||||
|
||||
@@ -22,9 +22,12 @@
|
||||
*/
|
||||
int prng_is_valid(int idx)
|
||||
{
|
||||
LTC_MUTEX_LOCK(<c_prng_mutex);
|
||||
if (idx < 0 || idx >= TAB_SIZE || prng_descriptor[idx].name == NULL) {
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return CRYPT_INVALID_PRNG;
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,10 @@ int register_cipher(const struct ltc_cipher_descriptor *cipher)
|
||||
LTC_ARGCHK(cipher != NULL);
|
||||
|
||||
/* is it already registered? */
|
||||
LTC_MUTEX_LOCK(<c_cipher_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (cipher_descriptor[x].name != NULL && cipher_descriptor[x].ID == cipher->ID) {
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
@@ -37,11 +39,13 @@ int register_cipher(const struct ltc_cipher_descriptor *cipher)
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (cipher_descriptor[x].name == NULL) {
|
||||
XMEMCPY(&cipher_descriptor[x], cipher, sizeof(struct ltc_cipher_descriptor));
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
/* no spot */
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,10 @@ int register_hash(const struct ltc_hash_descriptor *hash)
|
||||
LTC_ARGCHK(hash != NULL);
|
||||
|
||||
/* is it already registered? */
|
||||
LTC_MUTEX_LOCK(<c_hash_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (memcmp(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor)) == 0) {
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
@@ -37,11 +39,13 @@ int register_hash(const struct ltc_hash_descriptor *hash)
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (hash_descriptor[x].name == NULL) {
|
||||
XMEMCPY(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor));
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
/* no spot */
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,10 @@ int register_prng(const struct ltc_prng_descriptor *prng)
|
||||
LTC_ARGCHK(prng != NULL);
|
||||
|
||||
/* is it already registered? */
|
||||
LTC_MUTEX_LOCK(<c_prng_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (memcmp(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor)) == 0) {
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
@@ -37,11 +39,13 @@ int register_prng(const struct ltc_prng_descriptor *prng)
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (prng_descriptor[x].name == NULL) {
|
||||
XMEMCPY(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor));
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
/* no spot */
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,13 +27,16 @@ int unregister_cipher(const struct ltc_cipher_descriptor *cipher)
|
||||
LTC_ARGCHK(cipher != NULL);
|
||||
|
||||
/* is it already registered? */
|
||||
LTC_MUTEX_LOCK(<c_cipher_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (memcmp(&cipher_descriptor[x], cipher, sizeof(struct ltc_cipher_descriptor)) == 0) {
|
||||
cipher_descriptor[x].name = NULL;
|
||||
cipher_descriptor[x].ID = 255;
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_cipher_mutex);
|
||||
return CRYPT_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,15 @@ int unregister_hash(const struct ltc_hash_descriptor *hash)
|
||||
LTC_ARGCHK(hash != NULL);
|
||||
|
||||
/* is it already registered? */
|
||||
LTC_MUTEX_LOCK(<c_hash_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (memcmp(&hash_descriptor[x], hash, sizeof(struct ltc_hash_descriptor)) == 0) {
|
||||
hash_descriptor[x].name = NULL;
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_hash_mutex);
|
||||
return CRYPT_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,14 +25,17 @@ int unregister_prng(const struct ltc_prng_descriptor *prng)
|
||||
int x;
|
||||
|
||||
LTC_ARGCHK(prng != NULL);
|
||||
|
||||
|
||||
/* is it already registered? */
|
||||
LTC_MUTEX_LOCK(<c_prng_mutex);
|
||||
for (x = 0; x < TAB_SIZE; x++) {
|
||||
if (memcmp(&prng_descriptor[x], prng, sizeof(struct ltc_prng_descriptor)) != 0) {
|
||||
prng_descriptor[x].name = NULL;
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
}
|
||||
LTC_MUTEX_UNLOCK(<c_prng_mutex);
|
||||
return CRYPT_ERROR;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user