1 /*
2  * %CopyrightBegin%
3  *
4  * Copyright Ericsson AB 2010-2018. All Rights Reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * %CopyrightEnd%
19  */
20 
21 #include "fips.h"
22 
info_fips(ErlNifEnv * env,int argc,const ERL_NIF_TERM argv[])23 ERL_NIF_TERM info_fips(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
24 {
25 #ifdef FIPS_SUPPORT
26     return FIPS_mode() ? atom_enabled : atom_not_enabled;
27 #else
28     return atom_not_supported;
29 #endif
30 }
31 
enable_fips_mode(ErlNifEnv * env,int argc,const ERL_NIF_TERM argv[])32 ERL_NIF_TERM enable_fips_mode(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
33 {/* (Boolean) */
34     if (argv[0] == atom_true) {
35 #ifdef FIPS_SUPPORT
36         if (FIPS_mode_set(1)) {
37             return atom_true;
38         }
39 #endif
40         PRINTF_ERR0("CRYPTO: Could not setup FIPS mode");
41         return atom_false;
42     } else if (argv[0] == atom_false) {
43 #ifdef FIPS_SUPPORT
44         if (!FIPS_mode_set(0)) {
45             return atom_false;
46         }
47 #endif
48         return atom_true;
49     } else {
50         return enif_make_badarg(env);
51     }
52 }
53