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