xref: /openbsd-src/lib/libcrypto/sm2/sm2_err.c (revision aeccd9edd302fe990bf973797294a8e569b8ec99)
1 /*	$OpenBSD: sm2_err.c,v 1.2 2022/07/12 14:42:50 kn Exp $ */
2 /*
3  * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
4  *
5  * Licensed under the OpenSSL license (the "License").  You may not use
6  * this file except in compliance with the License.  You can obtain a copy
7  * in the file LICENSE in the source distribution or at
8  * https://www.openssl.org/source/license.html
9  */
10 
11 #ifndef OPENSSL_NO_SM2
12 
13 #include <openssl/err.h>
14 #include <openssl/sm2.h>
15 
16 #ifndef OPENSSL_NO_ERR
17 
18 #define ERR_FUNC(func) ERR_PACK(ERR_LIB_SM2,func,0)
19 #define ERR_REASON(reason) ERR_PACK(ERR_LIB_SM2,0,reason)
20 
21 static ERR_STRING_DATA SM2_str_functs[] = {
22 	{ERR_FUNC(0xfff), "CRYPTO_internal"},
23 	{0, NULL}
24 };
25 
26 static ERR_STRING_DATA SM2_str_reasons[] = {
27 	{ERR_REASON(SM2_R_ASN1_ERROR), "asn1 error"},
28 	{ERR_REASON(SM2_R_ASN5_ERROR), "asn5 error"},
29 	{ERR_REASON(SM2_R_BAD_SIGNATURE), "bad signature"},
30 	{ERR_REASON(SM2_R_BIGNUM_OUT_OF_RANGE), "bignum out of range"},
31 	{ERR_REASON(SM2_R_BUFFER_TOO_SMALL), "buffer too small"},
32 	{ERR_REASON(SM2_R_COORDINATES_OUT_OF_RANGE), "coordinates out of range"},
33 	{ERR_REASON(SM2_R_CURVE_DOES_NOT_SUPPORT_ECDH), "curve does not support ecdh"},
34 	{ERR_REASON(SM2_R_CURVE_DOES_NOT_SUPPORT_SIGNING), "curve does not support signing"},
35 	{ERR_REASON(SM2_R_D2I_ECPKPARAMETERS_FAILURE), "d2i ecpkparameters failure"},
36 	{ERR_REASON(SM2_R_DECODE_ERROR), "decode error"},
37 	{ERR_REASON(SM2_R_DIGEST_FAILURE), "digest calculation failure"},
38 	{ERR_REASON(SM2_R_DISCRIMINANT_IS_ZERO), "discriminant is zero"},
39 	{ERR_REASON(SM2_R_EC_GROUP_NEW_BY_NAME_FAILURE), "ec group new by name failure"},
40 	{ERR_REASON(SM2_R_FIELD_TOO_LARGE), "field too large"},
41 	{ERR_REASON(SM2_R_GF2M_NOT_SUPPORTED), "gf2m not supported"},
42 	{ERR_REASON(SM2_R_GROUP2PKPARAMETERS_FAILURE), "group2pkparameters failure"},
43 	{ERR_REASON(SM2_R_I2D_ECPKPARAMETERS_FAILURE), "i2d ecpkparameters failure"},
44 	{ERR_REASON(SM2_R_INCOMPATIBLE_OBJECTS), "incompatible objects"},
45 	{ERR_REASON(SM2_R_INVALID_ARGUMENT), "invalid argument"},
46 	{ERR_REASON(SM2_R_INVALID_COMPRESSED_POINT), "invalid compressed point"},
47 	{ERR_REASON(SM2_R_INVALID_COMPRESSION_BIT), "invalid compression bit"},
48 	{ERR_REASON(SM2_R_INVALID_CURVE), "invalid curve"},
49 	{ERR_REASON(SM2_R_INVALID_DIGEST), "invalid digest"},
50 	{ERR_REASON(SM2_R_INVALID_DIGEST_TYPE), "invalid digest type"},
51 	{ERR_REASON(SM2_R_INVALID_ENCODING), "invalid encoding"},
52 	{ERR_REASON(SM2_R_INVALID_FIELD), "invalid field"},
53 	{ERR_REASON(SM2_R_INVALID_FORM), "invalid form"},
54 	{ERR_REASON(SM2_R_INVALID_GROUP_ORDER), "invalid group order"},
55 	{ERR_REASON(SM2_R_INVALID_KEY), "invalid key"},
56 	{ERR_REASON(SM2_R_INVALID_OUTPUT_LENGTH), "invalid output length"},
57 	{ERR_REASON(SM2_R_INVALID_PEER_KEY), "invalid peer key"},
58 	{ERR_REASON(SM2_R_INVALID_PENTANOMIAL_BASIS), "invalid pentanomial basis"},
59 	{ERR_REASON(SM2_R_INVALID_PRIVATE_KEY), "invalid private key"},
60 	{ERR_REASON(SM2_R_INVALID_TRINOMIAL_BASIS), "invalid trinomial basis"},
61 	{ERR_REASON(SM2_R_KDF_FAILURE), "kdf calculation failure"},
62 	{ERR_REASON(SM2_R_KDF_PARAMETER_ERROR), "kdf parameter error"},
63 	{ERR_REASON(SM2_R_KEYS_NOT_SET), "keys not set"},
64 	{ERR_REASON(SM2_R_MISSING_PARAMETERS), "missing parameters"},
65 	{ERR_REASON(SM2_R_MISSING_PRIVATE_KEY), "missing private key"},
66 	{ERR_REASON(SM2_R_NEED_NEW_SETUP_VALUES), "need new setup values"},
67 	{ERR_REASON(SM2_R_NOT_A_NIST_PRIME), "not a NIST prime"},
68 	{ERR_REASON(SM2_R_NOT_IMPLEMENTED), "not implemented"},
69 	{ERR_REASON(SM2_R_NOT_INITIALIZED), "not initialized"},
70 	{ERR_REASON(SM2_R_NO_PARAMETERS_SET), "no parameters set"},
71 	{ERR_REASON(SM2_R_NO_PRIVATE_VALUE), "no private value"},
72 	{ERR_REASON(SM2_R_OPERATION_NOT_SUPPORTED), "operation not supported"},
73 	{ERR_REASON(SM2_R_PASSED_NULL_PARAMETER), "passed null parameter"},
74 	{ERR_REASON(SM2_R_PEER_KEY_ERROR), "peer key error"},
75 	{ERR_REASON(SM2_R_PKPARAMETERS2GROUP_FAILURE), "pkparameters2group failure"},
76 	{ERR_REASON(SM2_R_POINT_ARITHMETIC_FAILURE), "point arithmetic failure"},
77 	{ERR_REASON(SM2_R_POINT_AT_INFINITY), "point at infinity"},
78 	{ERR_REASON(SM2_R_POINT_IS_NOT_ON_CURVE), "point is not on curve"},
79 	{ERR_REASON(SM2_R_RANDOM_NUMBER_GENERATION_FAILED), "random number generation failed"},
80 	{ERR_REASON(SM2_R_SHARED_INFO_ERROR), "shared info error"},
81 	{ERR_REASON(SM2_R_SLOT_FULL), "slot full"},
82 	{ERR_REASON(SM2_R_UNDEFINED_GENERATOR), "undefined generator"},
83 	{ERR_REASON(SM2_R_UNDEFINED_ORDER), "undefined order"},
84 	{ERR_REASON(SM2_R_UNKNOWN_GROUP), "unknown group"},
85 	{ERR_REASON(SM2_R_UNKNOWN_ORDER), "unknown order"},
86 	{ERR_REASON(SM2_R_UNSUPPORTED_FIELD), "unsupported field"},
87 	{ERR_REASON(SM2_R_WRONG_CURVE_PARAMETERS), "wrong curve parameters"},
88 	{ERR_REASON(SM2_R_WRONG_ORDER), "wrong order"},
89 	{0, NULL}
90 };
91 
92 #endif
93 
94 void
ERR_load_SM2_strings(void)95 ERR_load_SM2_strings(void)
96 {
97 #ifndef OPENSSL_NO_ERR
98 	if (ERR_func_error_string(SM2_str_functs[0].error) == NULL) {
99 		ERR_load_strings(0, SM2_str_functs);
100 		ERR_load_strings(0, SM2_str_reasons);
101 	}
102 #endif
103 }
104 
105 #endif /* OPENSSL_NO_SM2 */
106