1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4 
5 /**
6   @file crypt_find_cipher_id.c
7   Find cipher by ID, Tom St Denis
8 */
9 
10 /**
11    Find a cipher by ID number
12    @param ID    The ID (not same as index) of the cipher to find
13    @return >= 0 if found, -1 if not present
14 */
find_cipher_id(unsigned char ID)15 int find_cipher_id(unsigned char ID)
16 {
17    int x;
18    LTC_MUTEX_LOCK(&ltc_cipher_mutex);
19    for (x = 0; x < TAB_SIZE && cipher_descriptor[x] != NULL; x++) {
20        if (cipher_descriptor[x]->ID == ID) {
21           LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
22           return x;
23        }
24    }
25    LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
26    return -1;
27 }
28