components/openssl/openssl-1.0.0/engines/devcrypto/e_devcrypto_err.c
changeset 1158 227137d9fbce
parent 1157 65a016eaa866
child 1159 24e95e0bf738
equal deleted inserted replaced
1157:65a016eaa866 1158:227137d9fbce
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License (the "License").
       
     6  * You may not use this file except in compliance with the License.
       
     7  *
       
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9  * or http://www.opensolaris.org/os/licensing.
       
    10  * See the License for the specific language governing permissions
       
    11  * and limitations under the License.
       
    12  *
       
    13  * When distributing Covered Code, include this CDDL HEADER in each
       
    14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15  * If applicable, add the following below this CDDL HEADER, with the
       
    16  * fields enclosed by brackets "[]" replaced with your own identifying
       
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    18  *
       
    19  * CDDL HEADER END
       
    20  *
       
    21  * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
       
    22  */
       
    23 
       
    24 #include "e_devcrypto_err.h"
       
    25 
       
    26 /* BEGIN ERROR CODES */
       
    27 
       
    28 #ifndef OPENSSL_NO_ERR
       
    29 
       
    30 #define	ERR_FUNC(func) ERR_PACK(0, func, 0)
       
    31 #define	ERR_REASON(reason) ERR_PACK(0, 0, reason)
       
    32 
       
    33 static ERR_STRING_DATA devcrypto_str_functs[]=
       
    34 {
       
    35 { ERR_FUNC(DEVC_F_INIT),		"DEVCRYPTO_INIT"},
       
    36 { ERR_FUNC(DEVC_F_DESTROY),		"DEVCRYPTO_DESTROY"},
       
    37 { ERR_FUNC(DEVC_F_FINISH),		"DEVCRYPTO_FINISH"},
       
    38 { ERR_FUNC(DEVC_F_CIPHER_INIT),		"DEVCRYPTO_CIPHER_INIT"},
       
    39 { ERR_FUNC(DEVC_F_CIPHER_DO_CIPHER),	"DEVCRYPTO_CIPHER_DO_CIPHER"},
       
    40 { ERR_FUNC(DEVC_F_CIPHER_CLEANUP),	"DEVCRYPTO_CIPHER_CLEANUP"},
       
    41 { 0, NULL}
       
    42 };
       
    43 
       
    44 static ERR_STRING_DATA devcrypto_str_reasons[]=
       
    45 {
       
    46 { ERR_REASON(DEVC_R_CIPHER_KEY), "invalid cipher key"},
       
    47 { ERR_REASON(DEVC_R_CIPHER_NID), "invalid cipher nid"},
       
    48 { ERR_REASON(DEVC_R_KEY_OR_IV_LEN_PROBLEM), "IV or key length incorrect"},
       
    49 { ERR_REASON(DEVC_R_MECH_STRING), "convert cipher type to string failed"},
       
    50 { ERR_REASON(DEVC_R_FIND_SLOT_BY_MECH),
       
    51 	"no hardware providers support this cipher"},
       
    52 { ERR_REASON(DEVC_R_OPEN_SESSION), "CRYPTO_OPEN_SESSION failed"},
       
    53 { ERR_REASON(DEVC_R_GET_MECHANISM_NUMBER),
       
    54 	"CRYPTO_GET_MECHANISM_NUMBER failed"},
       
    55 { ERR_REASON(DEVC_R_ENCRYPT_INIT),  	"CRYPTO_ENCRYPT_INIT failed"},
       
    56 { ERR_REASON(DEVC_R_ENCRYPT_UPDATE),  	"CRYPTO_ENCRYPT_UPDATE failed"},
       
    57 { ERR_REASON(DEVC_R_ENCRYPT_FINAL),  	"CRYPTO_ENCRYPT_FINAL failed"},
       
    58 { ERR_REASON(DEVC_R_DECRYPT_INIT),  	"CRYPTO_DECRYPT_INIT failed"},
       
    59 { ERR_REASON(DEVC_R_DECRYPT_UPDATE),  	"CRYPTO_DECRYPT_UPDATE failed"},
       
    60 { ERR_REASON(DEVC_R_DECRYPT_FINAL),  	"CRYPTO_DECRYPT_FINAL failed"},
       
    61 { ERR_REASON(DEVC_R_CLOSE_SESSION),  	"CRYPTO_CLOSE_SESSION failed"},
       
    62 { 0, NULL}
       
    63 };
       
    64 #endif	/* OPENSSL_NO_ERR */
       
    65 
       
    66 
       
    67 #ifdef DEVCRYPTO_LIB_NAME
       
    68 static ERR_STRING_DATA DEVCRYPTO_lib_name[]=
       
    69 {
       
    70 {0, DEVCRYPTO_LIB_NAME},
       
    71 {0, NULL}
       
    72 };
       
    73 #endif
       
    74 
       
    75 static int devcrypto_error_code = 0;
       
    76 static int devcrypto_error_init = 1;
       
    77 
       
    78 static void
       
    79 ERR_load_devcrypto_strings(void)
       
    80 {
       
    81 	if (devcrypto_error_code == 0)
       
    82 		devcrypto_error_code = ERR_get_next_error_library();
       
    83 
       
    84 	if (devcrypto_error_init) {
       
    85 		devcrypto_error_init = 0;
       
    86 
       
    87 #ifndef OPENSSL_NO_ERR
       
    88 		ERR_load_strings(devcrypto_error_code, devcrypto_str_functs);
       
    89 		ERR_load_strings(devcrypto_error_code, devcrypto_str_reasons);
       
    90 #endif
       
    91 
       
    92 #ifdef DEVCRYPTO_LIB_NAME
       
    93 		DEVCRYPTO_lib_name->error =
       
    94 		    ERR_PACK(devcrypto_error_code, 0, 0);
       
    95 		ERR_load_strings(0, DEVCRYPTO_lib_name);
       
    96 #endif
       
    97 	}
       
    98 }
       
    99 
       
   100 static void
       
   101 ERR_unload_devcrypto_strings(void)
       
   102 {
       
   103 	if (devcrypto_error_init == 0) {
       
   104 #ifndef OPENSSL_NO_ERR
       
   105 		ERR_unload_strings(devcrypto_error_code, devcrypto_str_functs);
       
   106 		ERR_unload_strings(devcrypto_error_code, devcrypto_str_reasons);
       
   107 #endif
       
   108 
       
   109 #ifdef DEVCRYPTO_LIB_NAME
       
   110 		ERR_unload_strings(0, DEVCRYPTO_lib_name);
       
   111 #endif
       
   112 		devcrypto_error_init = 1;
       
   113 	}
       
   114 }
       
   115 
       
   116 static void
       
   117 ERR_devcrypto_error(int function, int reason, char *file, int line)
       
   118 {
       
   119 	if (devcrypto_error_code == 0)
       
   120 		devcrypto_error_code = ERR_get_next_error_library();
       
   121 	ERR_PUT_error(devcrypto_error_code, function, reason, file, line);
       
   122 }