From cb44612ccd4c71677b4d74885499764ffbd487aa Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Sat, 20 May 2017 09:04:31 +0800 Subject: [PATCH] update base58 --- .gitignore | 2 ++ crypto/base58/base58.c | 6 ++++-- crypto/base58/base58_err.c | 44 ++++++++++++++++++++++++++++++++++++++ crypto/base58/build.info | 3 ++- crypto/err/err.c | 2 ++ crypto/err/err_all.c | 5 +++++ crypto/err/openssl.ec | 1 + 7 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 crypto/base58/base58_err.c diff --git a/.gitignore b/.gitignore index 3bbef5c1..4a7e2aa7 100644 --- a/.gitignore +++ b/.gitignore @@ -177,3 +177,5 @@ crypto/opensslconf.h tool/c_rehash # exec file apps/gmssl + +include/openssl/srp.h diff --git a/crypto/base58/base58.c b/crypto/base58/base58.c index f3dfb4ed..8c52acf2 100644 --- a/crypto/base58/base58.c +++ b/crypto/base58/base58.c @@ -58,7 +58,7 @@ #include #include #include - +#include #include static const int8_t b58digits_map[] = { @@ -97,9 +97,11 @@ bool base58_decode(const char *b58, size_t b58sz, void *bin, size_t *binszp) for ( ; i < b58sz; ++i) { - if (b58u[i] & 0x80) + if (b58u[i] & 0x80) { // High-bit set on invalid digit + BASE58err(BASE58_F_BASE58_DECODE, BASE58_R_HIGHBIT_SET_ON_INVALID_DIGIT); return false; + } if (b58digits_map[b58u[i]] == -1) // Invalid base58 digit return false; diff --git a/crypto/base58/base58_err.c b/crypto/base58/base58_err.c new file mode 100644 index 00000000..9a034293 --- /dev/null +++ b/crypto/base58/base58_err.c @@ -0,0 +1,44 @@ +/* + * Generated by util/mkerr.pl DO NOT EDIT + * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the OpenSSL license (the "License"). You may not use + * 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 + */ + +#include +#include +#include + +/* BEGIN ERROR CODES */ +#ifndef OPENSSL_NO_ERR + +# define ERR_FUNC(func) ERR_PACK(ERR_LIB_BASE58,func,0) +# define ERR_REASON(reason) ERR_PACK(ERR_LIB_BASE58,0,reason) + +static ERR_STRING_DATA BASE58_str_functs[] = { + {ERR_FUNC(BASE58_F_BASE58_DECODE), "base58_decode"}, + {0, NULL} +}; + +static ERR_STRING_DATA BASE58_str_reasons[] = { + {ERR_REASON(BASE58_R_HIGHBIT_SET_ON_INVALID_DIGIT), + "highbit set on invalid digit"}, + {0, NULL} +}; + +#endif + +int ERR_load_BASE58_strings(void) +{ +#ifndef OPENSSL_NO_ERR + + if (ERR_func_error_string(BASE58_str_functs[0].error) == NULL) { + ERR_load_strings(0, BASE58_str_functs); + ERR_load_strings(0, BASE58_str_reasons); + } +#endif + return 1; +} diff --git a/crypto/base58/build.info b/crypto/base58/build.info index e32e83e7..329c15cb 100644 --- a/crypto/base58/build.info +++ b/crypto/base58/build.info @@ -1,2 +1,3 @@ LIBS=../../libcrypto -SOURCE[../../libcrypto]=base58.c +SOURCE[../../libcrypto]=base58.c base58_err.c + diff --git a/crypto/err/err.c b/crypto/err/err.c index a1a1e1a5..7f209432 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -73,6 +73,7 @@ static ERR_STRING_DATA ERR_str_libraries[] = { {ERR_PACK(ERR_LIB_SDF, 0, 0), "SDF routines"}, {ERR_PACK(ERR_LIB_SKF, 0, 0), "SKF routines"}, {ERR_PACK(ERR_LIB_SOF, 0, 0), "SOF routines"}, + {ERR_PACK(ERR_LIB_BASE58, 0, 0), "BASE58 routines"}, {0, NULL}, }; @@ -131,6 +132,7 @@ static ERR_STRING_DATA ERR_str_reasons[] = { {ERR_R_SDF_LIB, "SDF lib"}, {ERR_R_SKF_LIB, "SKF lib"}, {ERR_R_SOF_LIB, "SOF lib"}, + {ERR_R_BASE58_LIB, "BASE58 lib"}, {ERR_R_NESTED_ASN1_ERROR, "nested asn1 error"}, {ERR_R_MISSING_ASN1_EOS, "missing asn1 eos"}, diff --git a/crypto/err/err_all.c b/crypto/err/err_all.c index 634e2882..0bf62396 100644 --- a/crypto/err/err_all.c +++ b/crypto/err/err_all.c @@ -53,6 +53,8 @@ #include #include #include +#include + int err_load_crypto_strings_int(void) { @@ -157,6 +159,9 @@ int err_load_crypto_strings_int(void) # ifndef OPENSSL_NO_SOF ERR_load_SOF_strings() == 0 || # endif +# ifndef OPENSSL_NO_BASE58 + ERR_load_BASE58_strings() == 0 || +# endif #endif ERR_load_KDF_strings() == 0) return 0; diff --git a/crypto/err/openssl.ec b/crypto/err/openssl.ec index e6508150..a3c81743 100644 --- a/crypto/err/openssl.ec +++ b/crypto/err/openssl.ec @@ -49,6 +49,7 @@ L SAF include/openssl/gmsaf.h crypto/saf/saf_err.c L SDF include/openssl/gmsdf.h crypto/sdf/sdf_err.c L SKF include/openssl/gmskf.h crypto/skf/skf_err.c L SOF include/openssl/gmsof.h crypto/sof/sof_err.c +L BASE58 include/openssl/base58.h crypto/base58/base58_err.c # additional header files to be scanned for function names L NONE crypto/x509/x509_vfy.h NONE