1 // SPDX-License-Identifier: BSD-2-Clause
2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3  *
4  * LibTomCrypt is a library that provides various cryptographic
5  * algorithms in a highly modular and flexible manner.
6  *
7  * The library is free for all purposes without any express
8  * guarantee it works.
9  */
10 #include "tomcrypt_private.h"
11 
12 /**
13   @file crypt_inits.c
14 
15   Provide math library functions for dynamic languages
16   like Python - Larry Bugbee, February 2013
17 */
18 
19 
20 #ifdef LTM_DESC
init_LTM(void)21 void init_LTM(void)
22 {
23     ltc_mp = ltm_desc;
24 }
25 #endif
26 
27 #ifdef TFM_DESC
init_TFM(void)28 void init_TFM(void)
29 {
30     ltc_mp = tfm_desc;
31 }
32 #endif
33 
34 #ifdef GMP_DESC
init_GMP(void)35 void init_GMP(void)
36 {
37     ltc_mp = gmp_desc;
38 }
39 #endif
40 
crypt_mp_init(const char * mpi)41 int crypt_mp_init(const char* mpi)
42 {
43    if (mpi == NULL) return CRYPT_ERROR;
44    switch (mpi[0]) {
45 #ifdef LTM_DESC
46       case 'l':
47       case 'L':
48          ltc_mp = ltm_desc;
49          return CRYPT_OK;
50 #endif
51 #ifdef TFM_DESC
52       case 't':
53       case 'T':
54          ltc_mp = tfm_desc;
55          return CRYPT_OK;
56 #endif
57 #ifdef GMP_DESC
58       case 'g':
59       case 'G':
60          ltc_mp = gmp_desc;
61          return CRYPT_OK;
62 #endif
63 #ifdef EXT_MATH_LIB
64       case 'e':
65       case 'E':
66          {
67             extern ltc_math_descriptor EXT_MATH_LIB;
68             ltc_mp = EXT_MATH_LIB;
69          }
70 
71 #if defined(LTC_TEST_DBG)
72 #define NAME_VALUE(s) #s"="NAME(s)
73 #define NAME(s) #s
74          printf("EXT_MATH_LIB = %s\n", NAME_VALUE(EXT_MATH_LIB));
75 #undef NAME_VALUE
76 #undef NAME
77 #endif
78 
79          return CRYPT_OK;
80 #endif
81       default:
82 #if defined(LTC_TEST_DBG)
83          printf("Unknown/Invalid MPI provider: %s\n", mpi);
84 #endif
85          return CRYPT_ERROR;
86    }
87 }
88 
89 
90 /* ref:         $Format:%D$ */
91 /* git commit:  $Format:%H$ */
92 /* commit time: $Format:%ai$ */
93