| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2017-08-21 05:19:17 +08:00
										 |  |  |  * Copyright 2012-2017 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2012-07-04 21:15:10 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-12-06 20:40:06 +08:00
										 |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							| 
									
										
										
										
											2016-05-18 02:24:46 +08:00
										 |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							| 
									
										
										
										
											2012-07-04 21:15:10 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <openssl/crypto.h>
 | 
					
						
							| 
									
										
										
										
											2015-05-14 22:56:48 +08:00
										 |  |  | #include "internal/cryptlib.h"
 | 
					
						
							| 
									
										
										
										
											2012-07-04 21:15:10 +08:00
										 |  |  | #include <openssl/conf.h>
 | 
					
						
							|  |  |  | #include <openssl/x509.h>
 | 
					
						
							|  |  |  | #include <openssl/x509v3.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Algorithm configuration module. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int alg_module_init(CONF_IMODULE *md, const CONF *cnf) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     int i; | 
					
						
							|  |  |  |     const char *oid_section; | 
					
						
							|  |  |  |     STACK_OF(CONF_VALUE) *sktmp; | 
					
						
							|  |  |  |     CONF_VALUE *oval; | 
					
						
							| 
									
										
										
										
											2015-05-07 01:43:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     oid_section = CONF_imodule_get_value(md); | 
					
						
							| 
									
										
										
										
											2015-05-07 01:43:59 +08:00
										 |  |  |     if ((sktmp = NCONF_get_section(cnf, oid_section)) == NULL) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |         EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_ERROR_LOADING_SECTION); | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) { | 
					
						
							|  |  |  |         oval = sk_CONF_VALUE_value(sktmp, i); | 
					
						
							| 
									
										
										
										
											2015-05-07 02:56:14 +08:00
										 |  |  |         if (strcmp(oval->name, "fips_mode") == 0) { | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |             int m; | 
					
						
							|  |  |  |             if (!X509V3_get_value_bool(oval, &m)) { | 
					
						
							|  |  |  |                 EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_INVALID_FIPS_MODE); | 
					
						
							|  |  |  |                 return 0; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (m > 0) { | 
					
						
							|  |  |  |                 EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_FIPS_MODE_NOT_SUPPORTED); | 
					
						
							|  |  |  |                 return 0; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             EVPerr(EVP_F_ALG_MODULE_INIT, EVP_R_UNKNOWN_OPTION); | 
					
						
							|  |  |  |             ERR_add_error_data(4, "name=", oval->name, | 
					
						
							|  |  |  |                                ", value=", oval->value); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-07-04 21:15:10 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | void EVP_add_alg_module(void) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     CONF_module_add("alg_section", alg_module_init, 0); | 
					
						
							|  |  |  | } |