xref: /optee_os/core/lib/libtomcrypt/src/misc/crypt/crypt_unregister_cipher.c (revision 8411e6ad673d20c4742ed30c785e3f5cdea54dfa)
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4 
5 /**
6   @file crypt_unregister_cipher.c
7   Unregister a cipher, Tom St Denis
8 */
9 
10 /**
11   Unregister a cipher from the descriptor table
12   @param cipher   The cipher descriptor to remove
13   @return CRYPT_OK on success
14 */
unregister_cipher(const struct ltc_cipher_descriptor * cipher)15 int unregister_cipher(const struct ltc_cipher_descriptor *cipher)
16 {
17    int x;
18 
19    LTC_ARGCHK(cipher != NULL);
20 
21    /* is it already registered? */
22    LTC_MUTEX_LOCK(&ltc_cipher_mutex);
23    for (x = 0; x < TAB_SIZE; x++) {
24        if (cipher_descriptor[x] == cipher) {
25           cipher_descriptor[x] = NULL;
26           LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
27           return CRYPT_OK;
28        }
29    }
30    LTC_MUTEX_UNLOCK(&ltc_cipher_mutex);
31    return CRYPT_ERROR;
32 }
33