From bcad2eb8dd26c0a7a59547e2216c9ff064d4d6f8 Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Fri, 10 Sep 2021 11:29:16 +0800 Subject: [PATCH] update --- CMakeLists.txt | 131 ++- include/gmssl/aes.h | 54 +- include/gmssl/asn1.h | 56 +- include/gmssl/base64.h | 54 +- include/gmssl/block_cipher.h | 54 +- include/gmssl/chacha20.h | 54 +- include/gmssl/cms.h | 499 ++++++--- include/gmssl/crl.h | 54 +- include/gmssl/des.h | 54 +- include/gmssl/digest.h | 54 +- include/gmssl/error.h | 54 +- include/gmssl/gcm.h | 54 +- include/gmssl/gf128.h | 54 +- include/gmssl/hash_drbg.h | 54 +- include/gmssl/hex.h | 54 +- include/gmssl/hkdf.h | 54 +- include/gmssl/hmac.h | 54 +- include/gmssl/md5.h | 54 +- include/gmssl/oid.h | 73 +- include/gmssl/pbkdf2.h | 54 +- include/gmssl/pem.h | 54 +- include/gmssl/pkcs8.h | 54 +- include/gmssl/rand.h | 54 +- include/gmssl/rc4.h | 54 +- include/gmssl/sha1.h | 54 +- include/gmssl/sha2.h | 54 +- include/gmssl/sha3.h | 54 +- include/gmssl/sm2.h | 55 +- include/gmssl/sm3.h | 54 +- include/gmssl/sm4.h | 56 +- include/gmssl/sm9.h | 54 +- include/gmssl/tls.h | 54 +- include/gmssl/version.h | 41 + include/gmssl/x509.h | 94 +- include/gmssl/zuc.h | 54 +- sdf/sdf.h | 54 +- sdf/sdf_ext.c | 55 +- sdf/sdf_ext.h | 54 +- sdf/sdf_int.h | 54 +- sdf/sdf_lib.c | 55 +- sdf/sdf_meth.c | 57 +- sdf/sdf_sansec.c | 55 +- sdf/sdf_sansec.h | 55 +- sdf/sdfutil.c | 54 +- sdf/sgd.h | 54 +- skf/sgd.h | 55 +- skf/skf.h | 55 +- skf/skf_ext.c | 55 +- skf/skf_ext.h | 55 +- skf/skf_int.h | 55 +- skf/skf_lib.c | 55 +- skf/skf_meth.c | 55 +- skf/skf_prn.c | 55 +- skf/skf_wisec.c | 55 +- skf/skf_wisec.h | 55 +- skf/skfutil.c | 55 +- src/aes.c | 54 +- src/aes_modes.c | 54 +- src/asn1.c | 109 +- src/block_cipher.c | 54 +- src/chacha20.c | 54 +- src/cms.c | 1835 +++++++++++++++++++++++----------- src/debug.c | 60 +- src/des.c | 54 +- src/digest.c | 54 +- src/endian.h | 54 +- src/gcm.c | 54 +- src/gf128.c | 54 +- src/hash_drbg.c | 54 +- src/hex.c | 54 +- src/hkdf.c | 54 +- src/hmac.c | 54 +- src/md5.c | 54 +- src/mem.h | 54 +- src/nginx.c | 35 + src/oid.c | 59 +- src/pbkdf2.c | 54 +- src/pem.c | 54 +- src/pkcs8.c | 54 +- src/rand.c | 54 +- src/rc4.c | 54 +- src/sha1.c | 54 +- src/sha256.c | 54 +- src/sha512.c | 55 +- src/sm2_algo.c | 57 +- src/sm2_asn1.c | 62 +- src/sm2_lib.c | 66 +- src/sm2_prn.c | 60 +- src/sm3.c | 54 +- src/sm3_hmac.c | 54 +- src/sm4_common.c | 55 +- src/sm4_enc.c | 55 +- src/sm4_lcl.h | 55 +- src/sm4_modes.c | 54 +- src/sm4_setkey.c | 55 +- src/sm9_keygen.c | 54 +- src/sm9_math.c | 54 +- src/sm9_sign.c | 54 +- src/tlcp.c | 54 +- src/tls.c | 54 +- src/tls12.c | 54 +- src/tls13.c | 54 +- src/tls_trace.c | 54 +- src/version.c | 30 + src/x509_algor.c | 630 +++++++----- src/x509_asn1.c | 149 +-- src/x509_crl.c | 54 +- src/x509_ext.c | 168 ++-- src/x509_lib.c | 54 +- src/zuc_core.c | 54 +- src/zuc_eea.c | 55 +- src/zuc_eia.c | 55 +- tests/aestest.c | 54 +- tests/asn1test.c | 54 +- tests/base64test.c | 54 +- tests/block_ciphertest.c | 54 +- tests/chacha20test.c | 54 +- tests/cmstest.c | 646 +++++++++--- tests/destest.c | 54 +- tests/digesttest.c | 54 +- tests/gcmtest.c | 54 +- tests/gf128test.c | 54 +- tests/hash_drbgtest.c | 54 +- tests/hkdftest.c | 54 +- tests/hmactest.c | 54 +- tests/md5test.c | 54 +- tests/oidtest.c | 54 +- tests/pbkdf2test.c | 54 +- tests/pkcs8test.c | 54 +- tests/rc4test.c | 54 +- tests/sha1test.c | 54 +- tests/sha224test.c | 54 +- tests/sha256test.c | 54 +- tests/sha384test.c | 54 +- tests/sha512test.c | 54 +- tests/sm2asn1test.c | 54 +- tests/sm2test.c | 54 +- tests/sm3test.c | 55 +- tests/sm4cbctest.c | 54 +- tests/sm4test.c | 54 +- tests/tlstest.c | 54 +- tests/x509_algortest.c | 241 +++++ tests/x509test.c | 54 +- tests/zuctest.c | 55 +- tools/README.md | 15 +- tools/certgen.c | 112 +-- tools/certparse.c | 44 + tools/certverify.c | 59 +- tools/certview.c | 76 -- tools/digest.c | 54 +- tools/hmac.c | 54 +- tools/oid.c | 113 --- tools/pkcs8gen.c | 54 +- tools/pkcs8view.c | 72 -- tools/reqgen.c | 100 +- tools/reqparse.c | 81 ++ tools/reqsign.c | 54 +- tools/sm2decrypt.c | 149 +-- tools/sm2encrypt.c | 139 ++- tools/sm2gen.c | 70 -- tools/sm2keygen.c | 122 +++ tools/sm2pub.c | 79 -- tools/sm2sign.c | 153 +-- tools/sm2verify.c | 163 ++- tools/sm2view.c | 67 -- tools/sm3.c | 122 +++ tools/sm3hmac.c | 95 ++ tools/sm3sum.c | 81 -- tools/sm4speed.c | 55 +- tools/tlcp_client.c | 54 +- tools/tlcp_server.c | 54 +- tools/tls12_client.c | 56 +- tools/tls12_server.c | 56 +- tools/tls13_client.c | 54 +- tools/tls13_server.c | 54 +- 175 files changed, 5701 insertions(+), 8583 deletions(-) mode change 100755 => 100644 include/gmssl/cms.h mode change 100755 => 100644 include/gmssl/md5.h mode change 100755 => 100644 include/gmssl/sha1.h mode change 100755 => 100644 include/gmssl/sha2.h mode change 100755 => 100644 include/gmssl/sm3.h create mode 100644 include/gmssl/version.h mode change 100755 => 100644 include/gmssl/zuc.h mode change 100755 => 100644 src/md5.c create mode 100644 src/nginx.c mode change 100755 => 100644 src/sha1.c mode change 100755 => 100644 src/sha256.c mode change 100755 => 100644 src/sha512.c mode change 100755 => 100644 src/sm3.c create mode 100644 src/version.c create mode 100644 tests/x509_algortest.c create mode 100644 tools/certparse.c delete mode 100644 tools/certview.c delete mode 100644 tools/oid.c delete mode 100644 tools/pkcs8view.c create mode 100644 tools/reqparse.c delete mode 100644 tools/sm2gen.c create mode 100644 tools/sm2keygen.c delete mode 100644 tools/sm2pub.c delete mode 100644 tools/sm2view.c create mode 100644 tools/sm3.c create mode 100644 tools/sm3hmac.c delete mode 100644 tools/sm3sum.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 549df128..2ebed378 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,93 +46,84 @@ include_directories(include) add_library( gmssl - SHARED - + SHARED + src/hex.c src/debug.c src/rand.c - src/sm2_lib.c - src/sm2_prn.c + # default sm algors src/sm2_algo.c + src/sm2_lib.c src/sm2_asn1.c + src/sm2_prn.c src/sm3.c src/sm3_hmac.c src/sm4_common.c src/sm4_setkey.c src/sm4_enc.c src/sm4_modes.c + + # optional sm algors src/sm9_math.c src/zuc_core.c src/zuc_eea.c src/zuc_eia.c - src/hash_drbg.c - src/hmac.c - src/hkdf.c - src/pbkdf2.c - src/pkcs8.c - - src/oid.c - src/asn1.c - - src/rc4.c - src/md5.c - src/des.c + # optional nist algors src/aes.c src/aes_modes.c src/chacha20.c - src/sha1.c src/sha256.c src/sha512.c + # legacy algors + src/rc4.c + src/des.c + src/md5.c + src/sha1.c + + # schemes + src/hash_drbg.c + src/hmac.c + + # abstract src/digest.c src/block_cipher.c - src/gf128.c - src/gcm.c + # pkix + src/oid.c + src/asn1.c + src/base64.c + src/pem.c + src/pbkdf2.c + src/pkcs8.c src/x509_lib.c src/x509_asn1.c src/x509_ext.c src/x509_algor.c + src/cms.c - src/base64.c - src/pem.c + # for tls 1.3 + src/hkdf.c + src/gf128.c + src/gcm.c + # ssl/tls/tlcp src/tls.c src/tls_trace.c src/tls12.c src/tlcp.c src/tls13.c - src/cms.c - ) SET_TARGET_PROPERTIES(gmssl PROPERTIES VERSION 3.0 SOVERSION 3) +# tools -add_executable (digest tools/digest.c) -target_link_libraries (digest LINK_PUBLIC gmssl) - -add_executable (certview tools/certview.c) -target_link_libraries (certview LINK_PUBLIC gmssl) - -add_executable (certgen tools/certgen.c) -target_link_libraries (certgen LINK_PUBLIC gmssl) - -add_executable (certverify tools/certverify.c) -target_link_libraries (certverify LINK_PUBLIC gmssl) - -add_executable (reqgen tools/reqgen.c) -target_link_libraries (reqgen LINK_PUBLIC gmssl) - -add_executable (sm3sum tools/sm3sum.c) -target_link_libraries (sm3sum LINK_PUBLIC gmssl) - -add_executable (sm2gen tools/sm2gen.c) -target_link_libraries (sm2gen LINK_PUBLIC gmssl) - +add_executable (sm2keygen tools/sm2keygen.c) +target_link_libraries (sm2keygen LINK_PUBLIC gmssl) add_executable (sm2sign tools/sm2sign.c) target_link_libraries (sm2sign LINK_PUBLIC gmssl) add_executable (sm2verify tools/sm2verify.c) @@ -142,33 +133,42 @@ target_link_libraries (sm2encrypt LINK_PUBLIC gmssl) add_executable (sm2decrypt tools/sm2decrypt.c) target_link_libraries (sm2decrypt LINK_PUBLIC gmssl) -add_executable (pkcs8gen tools/pkcs8gen.c) -target_link_libraries (pkcs8gen LINK_PUBLIC gmssl) +add_executable (sm3 tools/sm3.c) +target_link_libraries (sm3 LINK_PUBLIC gmssl) +add_executable (sm3hmac tools/sm3hmac.c) +target_link_libraries (sm3hmac LINK_PUBLIC gmssl) -add_executable (sm2view tools/sm2view.c) -target_link_libraries (sm2view LINK_PUBLIC gmssl) +add_executable (reqgen tools/reqgen.c) +target_link_libraries (reqgen LINK_PUBLIC gmssl) +add_executable (reqparse tools/reqparse.c) +target_link_libraries (reqparse LINK_PUBLIC gmssl) -add_executable (pkcs8view tools/pkcs8view.c) -target_link_libraries (pkcs8view LINK_PUBLIC gmssl) +add_executable (certgen tools/certgen.c) +target_link_libraries (certgen LINK_PUBLIC gmssl) +add_executable (certparse tools/certparse.c) +target_link_libraries (certparse LINK_PUBLIC gmssl) +add_executable (certverify tools/certverify.c) +target_link_libraries (certverify LINK_PUBLIC gmssl) add_executable (tlcp_client tools/tlcp_client.c) target_link_libraries (tlcp_client LINK_PUBLIC gmssl) - add_executable (tlcp_server tools/tlcp_server.c) target_link_libraries (tlcp_server LINK_PUBLIC gmssl) - add_executable (tls12_client tools/tls12_client.c) target_link_libraries (tls12_client LINK_PUBLIC gmssl) - add_executable (tls12_server tools/tls12_server.c) target_link_libraries (tls12_server LINK_PUBLIC gmssl) - add_executable (tls13_client tools/tls13_client.c) target_link_libraries (tls13_client LINK_PUBLIC gmssl) add_executable (tls13_server tools/tls13_server.c) target_link_libraries (tls13_server LINK_PUBLIC gmssl) + + # tests +enable_testing() + + add_executable(sm2test tests/sm2test.c) target_link_libraries (sm2test LINK_PUBLIC gmssl) @@ -300,23 +300,8 @@ add_test(NAME x509 COMMAND x509test) add_test(NAME zuc COMMAND zuctest) - - - - -#add_executable(tlstest tests/tlstest.c) -#target_link_libraries (tlstest LINK_PUBLIC gmssl) - -# 安装可执行文件 -INSTALL(TARGETS digest certview certgen certverify reqgen sm3sum sm2gen sm2sign sm2verify sm2encrypt sm2decrypt pkcs8gen sm2view pkcs8view tlcp_client tlcp_server tls12_client tls12_server tls13_client tls13_server - RUNTIME DESTINATION bin - ) -# 安装动态库 -INSTALL(TARGETS gmssl - LIBRARY DESTINATION lib - ) -#安装头文件 -INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/gmssl - DESTINATION include - ) +INSTALL(TARGETS certparse certgen certverify reqgen sm3 sm2keygen sm2sign sm2verify sm2encrypt sm2decrypt tlcp_client tlcp_server tls12_client tls12_server tls13_client tls13_server + RUNTIME DESTINATION bin) +INSTALL(TARGETS gmssl LIBRARY DESTINATION lib) +INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/gmssl DESTINATION include) diff --git a/include/gmssl/aes.h b/include/gmssl/aes.h index 2c9a2650..30d24f57 100644 --- a/include/gmssl/aes.h +++ b/include/gmssl/aes.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/include/gmssl/asn1.h b/include/gmssl/asn1.h index 163e8ee7..43a73424 100644 --- a/include/gmssl/asn1.h +++ b/include/gmssl/asn1.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_ASN1_H @@ -269,6 +237,8 @@ int asn1_sequence_of_get_count(const ASN1_SEQUENCE_OF *a, size_t *count); int asn1_check(int expr); +int asn1_length_is_zero(size_t len); + #if __cplusplus diff --git a/include/gmssl/base64.h b/include/gmssl/base64.h index ec45d08a..5822307d 100644 --- a/include/gmssl/base64.h +++ b/include/gmssl/base64.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/include/gmssl/block_cipher.h b/include/gmssl/block_cipher.h index a357b9c8..6b031367 100644 --- a/include/gmssl/block_cipher.h +++ b/include/gmssl/block_cipher.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/include/gmssl/chacha20.h b/include/gmssl/chacha20.h index 24ebba81..6f856cbc 100644 --- a/include/gmssl/chacha20.h +++ b/include/gmssl/chacha20.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* RFC 8439 "ChaCha20 and Poly1305 for IETF Protocols" */ diff --git a/include/gmssl/cms.h b/include/gmssl/cms.h old mode 100755 new mode 100644 index 412c1439..2186afe1 --- a/include/gmssl/cms.h +++ b/include/gmssl/cms.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ @@ -80,112 +48,8 @@ typedef enum { -int cms_issuer_and_serial_number_from_certificate(const X509_NAME **issuer, - const uint8_t **serial_number, size_t *serial_number_len, - const X509_CERTIFICATE *cert); -int cms_public_key_from_certificate(const SM2_KEY **pub_key, - const X509_CERTIFICATE *cert); -int cms_issuer_and_serial_number_to_der(const X509_NAME *issuer, - const uint8_t *serial_number, size_t serial_number_len, - uint8_t **out, size_t *outlen); -int cms_issuer_and_serial_number_from_der(X509_NAME *issuer, - const uint8_t **serial_number, size_t *serial_number_len, - const uint8_t **in, size_t *inlen); - -const char *cms_content_type_name(int type); -int cms_content_type_to_der(int type, uint8_t **out, size_t *outlen); -int cms_content_type_from_der(int *type, const uint8_t **in, size_t *inlen); - - - -int cms_content_info_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent); - - -int cms_content_info_set_data(uint8_t *content_info, size_t *content_info_len, - const uint8_t *data, size_t datalen); -int cms_content_info_get_data(const uint8_t *content_info, size_t content_info_len, - const uint8_t **data, size_t *datalen); - - - - -int cms_data_print(FILE *fp, const uint8_t *in, size_t inlen, int format, int indent); - - - -int cms_signer_info_to_der(const X509_NAME *issuer, - const uint8_t *serial_number, size_t serial_number_len, int digest_algor, - const uint8_t *authed_attrs, size_t authed_attrs_len, - const uint8_t *enced_digest, size_t enced_digest_len, - const uint8_t *unauthed_attrs, size_t unauthed_attrs_len, - uint8_t **out, size_t *outlen); - -int cms_signer_info_from_der(X509_NAME *issuer, - const uint8_t **serial_number, size_t *serial_number_len, - int *digest_algor, - const uint8_t **authed_attrs, size_t *authed_attrs_len, - int *sign_algor, - const uint8_t **enced_digest, size_t *enced_digest_len, - const uint8_t **unauthed_attrs, size_t *unauthed_attrs_len, - const uint8_t **in, size_t *inlen); - -int cms_signer_info_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent); - -int cms_signer_info_sign_to_der(const SM2_KEY *sm2_key, const SM3_CTX *sm3_ctx, - const X509_NAME *issuer, const uint8_t *serial_number, size_t serial_number_len, - const uint8_t *authed_attrs, size_t authed_attrs_len, - const uint8_t *unauthed_attrs, size_t unauthed_attrs_len, - uint8_t **out, size_t *outlen); - -int cms_signer_info_verify_from_der( - const SM2_KEY *sm2_key, const SM3_CTX *sm3_ctx, - X509_NAME *issuer, const uint8_t **serial_number, size_t *serial_number_len, - int *digest_algor, uint32_t *digest_nodes, size_t *digest_algor_nodes_count, - const uint8_t **authed_attrs, size_t *authed_attrs_len, - int *sign_algor, uint32_t *sign_algor_nodes, size_t *sign_algor_nodes_count, - const uint8_t **unauthed_attrs, size_t *unauthed_attrs_len, - const uint8_t **in, size_t *inlen); - -int cms_signed_data_to_der( - const int *digest_algors, const size_t digset_algors_count, - const int content_type, const uint8_t *content, const size_t content_len, - const X509_CERTIFICATE *certs, size_t certs_count, - const uint8_t **crls, const size_t *crls_lens, const size_t crls_count, - const uint8_t **signer_infos, size_t *signer_infos_lens, size_t signer_infos_count, - uint8_t **out, size_t *outlen); - -int cms_signed_data_from_der( - const uint8_t **digest_algors, size_t *digest_algors_len, - int *content_type, const uint8_t **content, size_t *content_len, - const uint8_t **certs, size_t *certs_len, - const uint8_t **crls, size_t *crls_len, - const uint8_t **signer_infos, size_t *signer_infos_len, - const uint8_t **in, size_t *inlen); - -int cms_signed_data_print(FILE *fp, const uint8_t *in, size_t inlen, int format, int indent); - -int cms_signed_data_sign_to_der(const SM2_KEY *sign_keys, const X509_CERTIFICATE *sign_certs, size_t sign_count, - int content_type, const uint8_t *content, size_t content_len, - const uint8_t **crls, size_t *crls_lens, size_t crls_count, - uint8_t **out, size_t *outlen); - -int cms_signed_data_verify_from_der(const uint8_t *signed_data, size_t signed_data_len); - - -int cms_sign(const SM2_KEY *sign_keys, - const X509_CERTIFICATE *sign_certs, size_t sign_count, - int content_type, const uint8_t *content, size_t content_len, - const uint8_t **crls, size_t *crls_lens, size_t crls_count, - uint8_t *content_info, size_t *content_info_len); - -int cms_encrypt(const uint8_t key[16], const uint8_t *in, size_t inlen, - uint8_t *out, size_t *outlen); - -int cms_decrypt(const uint8_t key[16], const uint8_t *in, size_t inlen, - int *content_type, uint8_t *out, size_t *outlen, - const uint8_t **shared_info1, size_t *shared_info1_len, - const uint8_t **shared_info2, size_t *shared_info2_len); +int cms_data_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent); int cms_enced_content_info_to_der(int enc_algor, const uint8_t *enc_iv, size_t enc_iv_len, int content_type, const uint8_t *enced_content, size_t enced_content_len, @@ -200,6 +64,345 @@ int cms_enced_content_info_from_der(int *content_type, const uint8_t **shared_info2, size_t *shared_info2_len, const uint8_t **in, size_t *inlen); +int cms_enced_content_info_print(FILE *fp, + int content_type, + int enc_algor, const uint8_t *enc_iv, size_t enc_iv_len, + const uint8_t *enced_content, size_t enced_content_len, + const uint8_t *shared_info1, size_t shared_info1_len, + const uint8_t *shared_info2, size_t shared_info2_len, + int format, int indent); + +int cms_enced_content_info_encrypt_to_der(const SM4_KEY *sm4_key, const uint8_t iv[16], + int content_type, const uint8_t *content, size_t content_len, + const uint8_t *shared_info1, size_t shared_info1_len, + const uint8_t *shared_info2, size_t shared_info2_len, + uint8_t **out, size_t *outlen); + +int cms_enced_content_info_decrypt_from_der(const SM4_KEY *key, + int *content_type, uint8_t *content, size_t *content_len, + const uint8_t **shared_info1, size_t *shared_info1_len, + const uint8_t **shared_info2, size_t *shared_info2_len, + const uint8_t **in, size_t *inlen); + +int cms_encrypted_data_to_der(int enc_algor, const uint8_t *enc_iv, size_t enc_iv_len, + int content_type, const uint8_t *enced_content, size_t enced_content_len, + const uint8_t *shared_info1, size_t shared_info1_len, + const uint8_t *shared_info2, size_t shared_info2_len, + uint8_t **out, size_t *outlen); + +int cms_encrypted_data_from_der(int *content_type, + int *enc_algor, const uint8_t **enc_iv, size_t *enc_iv_len, + const uint8_t **enced_content, size_t *enced_content_len, + const uint8_t **shared_info1, size_t *shared_info1_len, + const uint8_t **shared_info2, size_t *shared_info2_len, + const uint8_t **in, size_t *inlen); + +int cms_encrypted_data_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent); + +int cms_encrypted_data_encrypt_to_der(const SM4_KEY *sm4_key, const uint8_t iv[16], + int content_type, const uint8_t *content, size_t content_len, + const uint8_t *shared_info1, size_t shared_info1_len, + const uint8_t *shared_info2, size_t shared_info2_len, + uint8_t **out, size_t *outlen); + +int cms_encrypted_data_decrypt_from_der(const SM4_KEY *key, + int *content_type, uint8_t *content, size_t *content_len, + const uint8_t **shared_info1, size_t *shared_info1_len, + const uint8_t **shared_info2, size_t *shared_info2_len, + const uint8_t **in, size_t *inlen); + + +int cms_key_agreement_info_to_der(const SM2_KEY *pub_key, const X509_CERTIFICATE *cert, + const uint8_t *user_id, size_t user_id_len, uint8_t **out, size_t *outlen); + +int cms_key_agreement_info_from_der(SM2_KEY *pub_key, X509_CERTIFICATE *cert, + const uint8_t **user_id, size_t *user_id_len, const uint8_t **in, size_t *inlen); + +int cms_key_agreement_info_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent); + + +int cms_issuer_and_serial_number_from_certificate(const X509_NAME **issuer, + const uint8_t **serial_number, size_t *serial_number_len, + const X509_CERTIFICATE *cert); + +int cms_public_key_from_certificate(const SM2_KEY **sm2_key, + const X509_CERTIFICATE *cert); + +int cms_issuer_and_serial_number_to_der(const X509_NAME *issuer, + const uint8_t *serial_number, size_t serial_number_len, + uint8_t **out, size_t *outlen); + +int cms_issuer_and_serial_number_from_der(X509_NAME *issuer, + const uint8_t **serial_number, size_t *serial_number_len, + const uint8_t **in, size_t *inlen); + +int cms_issuer_and_serial_number_print(FILE *fp, + const X509_NAME *issuer, + const uint8_t *serial_number, size_t serial_number_len, + int format, int indent); + + + +int cms_recipient_info_from_x509_certificate( + const SM2_KEY **key, + const X509_NAME **issuer, + const uint8_t **serial_number, size_t *serial_number_len, + const X509_CERTIFICATE *cert); + +int cms_recipient_info_to_der(const X509_NAME *issuer, + const uint8_t *serial_number, size_t serial_number_len, + const uint8_t *enced_key, size_t enced_key_len, + uint8_t **out, size_t *outlen); + +int cms_recipient_info_from_der( + int *version, + X509_NAME *issuer, + const uint8_t **serial_number, size_t *serial_number_len, + int *pke_algor, const uint8_t **params, size_t *paramslen, + const uint8_t **enced_key, size_t *enced_key_len, + const uint8_t **in, size_t *inlen); + +int cms_recipient_info_print(FILE *fp, + int version, + const X509_NAME *issuer, const uint8_t *serial_number, size_t serial_number_len, + int pke_algor, const uint8_t *params, size_t paramslen, + const uint8_t *enced_key, size_t enced_key_len, + int format, int indent); + +int cms_recipient_info_encrypt_to_der(const SM2_KEY *sm2_key, + const X509_NAME *issuer, const uint8_t *serial_number, size_t serial_number_len, + const uint8_t *key, size_t keylen, + uint8_t **out, size_t *outlen); + +int cms_recipient_info_decrypt_from_der(const SM2_KEY *sm2_key, + X509_NAME *issuer, const uint8_t **serial_number, size_t *serial_number_len, + uint8_t *key, size_t *keylen, + const uint8_t **in, size_t *inlen); + + +int cms_enveloped_data_to_der(const uint8_t *rcpt_infos, size_t rcpt_infos_len, + int content_type, + int enc_algor, + const uint8_t *enc_iv, size_t enc_iv_len, + const uint8_t *enced_content, size_t enced_content_len, + const uint8_t *shared_info1, size_t shared_info1_len, + const uint8_t *shared_info2, size_t shared_info2_len, + const uint8_t **out, size_t *outlen); + +int cms_enveloped_data_from_der(const uint8_t **rcpt_infos, size_t *rcpt_infos_len, + int *content_type, + int *enc_algor, const uint8_t **enc_iv, size_t *enc_iv_len, + const uint8_t **enced_content, size_t *enced_content_len, + const uint8_t **shared_info1, size_t *shared_info1_len, + const uint8_t **shared_info2, size_t *shared_info2_len, + const uint8_t **in, size_t *inlen); + +int cms_enveloped_data_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent); + +int cms_enveloped_data_encrypt_to_der(const X509_CERTIFICATE *rcpt_certs, size_t rcpt_count, + int content_type, const uint8_t *content, size_t content_len, + const uint8_t *shared_info1, size_t shared_info1_len, + const uint8_t *shared_info2, size_t shared_info2_len, + uint8_t **out, size_t *outlen); + +int cms_enveloped_data_decrypt_from_der( + const SM2_KEY *sm2_key, const X509_CERTIFICATE *cert, // 应该用证书还是issuer_and_serial_number? + int *content_type, uint8_t *content, size_t *content_len, + const uint8_t **shared_info1, size_t *shared_info1_len, + const uint8_t **shared_info2, size_t *shared_info2_len, + const uint8_t **in, size_t *inlen); + + +const char *cms_content_type_name(int type); +int cms_content_type_to_der(int type, uint8_t **out, size_t *outlen); +int cms_content_type_from_der(int *type, const uint8_t **in, size_t *inlen); + +int cms_content_info_to_der(int content_type, const uint8_t *content, size_t content_len, + uint8_t **out, size_t *outlen); + +int cms_content_info_from_der(int *content_type, const uint8_t **content, size_t *content_len, + const uint8_t **in, size_t *inlen); + + + + +int cms_signer_info_to_der( + const X509_NAME *issuer, + const uint8_t *serial_number, size_t serial_number_len, + int digest_algor, + const uint8_t *authed_attrs, size_t authed_attrs_len, + const uint8_t *enced_digest, size_t enced_digest_len, + const uint8_t *unauthed_attrs, size_t unauthed_attrs_len, + uint8_t **out, size_t *outlen); + +int cms_signer_info_from_der(X509_NAME *issuer, + const uint8_t **serial_number, size_t *serial_number_len, + int *digest_algor, + const uint8_t **authed_attrs, size_t *authed_attrs_len, + int *sign_algor, + const uint8_t **enced_digest, size_t *enced_digest_len, + const uint8_t **unauthed_attrs, size_t *unauthed_attrs_len, + const uint8_t **in, size_t *inlen); + +int cms_signer_info_print(FILE *fp, + int version, + const X509_NAME *issuer, const uint8_t *serial_number, size_t serial_number_len, + int digest_algor, const uint8_t *digest_params, size_t digest_params_len, + const uint8_t *authed_attrs, size_t authed_attrs_len, + int sign_algor, const uint8_t *sign_params, size_t sign_params_len, + const uint8_t *sig, size_t siglen, + const uint8_t *unauthed_attrs, size_t unauthed_attrs_len, + int format, int indent); + +int cms_signer_info_sign_to_der(const SM2_KEY *sm2_key, const SM3_CTX *sm3_ctx, + const X509_NAME *issuer, const uint8_t *serial_number, size_t serial_number_len, + const uint8_t *authed_attrs, size_t authed_attrs_len, + const uint8_t *unauthed_attrs, size_t unauthed_attrs_len, + uint8_t **out, size_t *outlen); + +int cms_signer_info_verify( + const SM2_KEY *sm2_key, const SM3_CTX *sm3_ctx, + const uint8_t *authed_attrs, size_t authed_attrs_len, + const uint8_t *sig, size_t siglen); + + +int cms_signed_data_to_der( + const int *digest_algors, const size_t digest_algors_count, + const int content_type, const uint8_t *content, const size_t content_len, + const X509_CERTIFICATE *certs, size_t certs_count, + const uint8_t **crls, const size_t *crls_lens, const size_t crls_count, + const uint8_t **signer_infos, size_t *signer_infos_lens, size_t signer_infos_count, + uint8_t **out, size_t *outlen); + +int cms_signed_data_from_der( + const uint8_t **digest_algors, size_t *digest_algors_len, + int *content_type, const uint8_t **content, size_t *content_len, + const uint8_t **certs, size_t *certs_len, + const uint8_t **crls, size_t *crls_len, + const uint8_t **signer_infos, size_t *signer_infos_len, + const uint8_t **in, size_t *inlen); + +int cms_signed_data_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent); + +int cms_signed_data_sign_to_der(const SM2_KEY *sign_keys, + const X509_CERTIFICATE *sign_certs, size_t sign_count, + int content_type, const uint8_t *content, size_t content_len, + const uint8_t *crls, size_t crls_len, + uint8_t **out, size_t *outlen); + +int cms_signed_data_verify_from_der( + const uint8_t **digest_algors, size_t *digest_algors_len, + int *content_type, const uint8_t **content, size_t *content_len, + const uint8_t **certs, size_t *certs_len, + const uint8_t **crls, size_t *crls_len, + const uint8_t **signer_infos, size_t *signer_infos_len, + const uint8_t **in, size_t *inlen); + +int cms_signed_data_verify( + int content_type, const uint8_t *content, size_t content_len, // 被签名的到底是什么数据? + const uint8_t *certs, size_t certs_len, + const uint8_t *signer_infos, size_t signer_infos_len); + + +int cms_signed_and_enveloped_data_to_der( + int version, + const uint8_t *rcpt_infos, size_t rcpt_infos_len, + const int *digest_algors, size_t digest_algors_count, + int content_type, + int enc_algor, const uint8_t *enc_iv, size_t enc_iv_len, + const uint8_t *enced_content, size_t enced_content_len, + const uint8_t *shared_info1, size_t shared_info1_len, + const uint8_t *shared_info2, size_t shared_info2_len, + const X509_CERTIFICATE *certs, size_t certs_count, + const uint8_t *crls, size_t crls_count, + const uint8_t signer_infos, size_t signer_infos_len); + +int cms_signed_and_enveloped_data_from_der( + int *version, + const uint8_t **rcpt_infos, size_t *rcpt_infos_len, + const uint8_t **dgst_algors, size_t *dgst_algors_len, + int *content_type, + int *enc_algor, const uint8_t **enc_iv, size_t *enc_iv_len, + const uint8_t **enced_content, size_t *enced_content_len, + const uint8_t **shared_info1, size_t *shared_info1_len, + const uint8_t **shared_info2, size_t *shared_info2_len, + const uint8_t **certs, size_t *certs_len, + const uint8_t **crls, size_t *crls_len, + const uint8_t **signer_infos, size_t *signer_infos_len, + const uint8_t **in, size_t *inlen); + +int cms_signed_and_enveloped_data_print(FILE *fp, const uint8_t *a, size_t alen, + int format, int indent); + + + + +int cms_signed_and_enveloped_data_sign_encrypt_to_der( + const SM2_KEY *sign_keys, const X509_CERTIFICATE *sign_certs, size_t sign_count, + const uint8_t *sign_crls, const size_t sign_crls_len, + const X509_CERTIFICATE *rcpt_certs, size_t rcpt_count, + int content_type, const uint8_t *content, size_t content_len, + const uint8_t *shared_info1, size_t shared_info1_len, + const uint8_t *shared_info2, size_t shared_info2_len, + uint8_t **out, size_t *outlen); + + +int cms_signed_and_enveloped_data_decrypt_verify_from_der( + const SM2_KEY *dec_key, const X509_CERTIFICATE *dec_cert, + const uint8_t **rcpt_infos, size_t *rcpt_infos_len, + const uint8_t **dgst_algors, size_t *dgst_algors_len, + int *content_type, + int *enc_algor, const uint8_t **enc_iv, size_t *enc_iv_len, + const uint8_t **enced_content, size_t *enced_content_len, + const uint8_t **shared_info1, size_t *shared_info1_len, + const uint8_t **shared_info2, size_t *shared_info2_len, + const uint8_t **certs, size_t *certs_len, + const uint8_t **crls, size_t *crls_len, + const uint8_t **signer_infos, size_t *signer_infos_len); + + +/* +下面是预计export的函数 +*/ + +int cms_content_info_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent); + + +int cms_encrypt(const uint8_t key[16], const uint8_t *in, size_t inlen, + uint8_t *out, size_t *outlen); + +int cms_decrypt(const uint8_t key[16], const uint8_t *in, size_t inlen, + int *content_type, uint8_t *out, size_t *outlen); + +int cms_seal(const X509_CERTIFICATE *rcpt_certs, size_t rcpt_count, + const uint8_t *in, size_t inlen, + uint8_t *out, size_t *outlen); + +int cms_open(const SM2_KEY *sm2_key, const X509_CERTIFICATE *cert, + const uint8_t *in, size_t inlen, + int *content_type, uint8_t *out, size_t *outlen); + +int cms_sign(const SM2_KEY *sign_keys, const X509_CERTIFICATE *sign_certs, size_t sign_count, + const uint8_t *in, size_t inlen, uint8_t *out, size_t *outlen); + +int cms_verify(int *content_type, const uint8_t **content, size_t *content_len, + const uint8_t **certs, size_t *certs_len, + const uint8_t **crls, size_t *crls_len, + const uint8_t **signer_infos, size_t *signer_infos_len, + const uint8_t *cms, size_t cmslen); + +int cms_sign_and_seal(const SM2_KEY *sign_keys, + const X509_CERTIFICATE *sign_certs, size_t sign_count, + const X509_CERTIFICATE *rcpt_certs, size_t rcpt_count, + const uint8_t *in, size_t inlen, + uint8_t *out, size_t *outlen); + +int cms_open_and_verify( + const SM2_KEY *sm2_key, const X509_CERTIFICATE *cert, + const uint8_t *in, size_t inlen, + int *content_type, uint8_t *out, size_t *outlen); + + #ifdef __cplusplus } diff --git a/include/gmssl/crl.h b/include/gmssl/crl.h index 43044202..bdf7bfa1 100644 --- a/include/gmssl/crl.h +++ b/include/gmssl/crl.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/include/gmssl/des.h b/include/gmssl/des.h index f879d64e..2fb0873e 100644 --- a/include/gmssl/des.h +++ b/include/gmssl/des.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* FIPS PUB 46-3 "Data Encryption Standard (DES)" */ diff --git a/include/gmssl/digest.h b/include/gmssl/digest.h index 9633dedf..78fb863f 100644 --- a/include/gmssl/digest.h +++ b/include/gmssl/digest.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/include/gmssl/error.h b/include/gmssl/error.h index c4ec5f09..49f14b9a 100644 --- a/include/gmssl/error.h +++ b/include/gmssl/error.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/include/gmssl/gcm.h b/include/gmssl/gcm.h index ce7035ad..7a9afe18 100644 --- a/include/gmssl/gcm.h +++ b/include/gmssl/gcm.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_GCM_H diff --git a/include/gmssl/gf128.h b/include/gmssl/gf128.h index a795619e..e7fd268c 100644 --- a/include/gmssl/gf128.h +++ b/include/gmssl/gf128.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* GF(2^128) defined by f(x) = x^128 + x^7 + x^2 + x + 1 diff --git a/include/gmssl/hash_drbg.h b/include/gmssl/hash_drbg.h index 7f110110..a0b86e61 100644 --- a/include/gmssl/hash_drbg.h +++ b/include/gmssl/hash_drbg.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* NIST SP800-90A Rev.1 "Recommendation for Random Number Generation diff --git a/include/gmssl/hex.h b/include/gmssl/hex.h index 466019a7..c5515ebf 100644 --- a/include/gmssl/hex.h +++ b/include/gmssl/hex.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/include/gmssl/hkdf.h b/include/gmssl/hkdf.h index 85c0dddf..c2f52426 100644 --- a/include/gmssl/hkdf.h +++ b/include/gmssl/hkdf.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ // RFC 5869 diff --git a/include/gmssl/hmac.h b/include/gmssl/hmac.h index 62511e85..4a3a3cec 100644 --- a/include/gmssl/hmac.h +++ b/include/gmssl/hmac.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_HMAC_H diff --git a/include/gmssl/md5.h b/include/gmssl/md5.h old mode 100755 new mode 100644 index e388690c..e464e3ca --- a/include/gmssl/md5.h +++ b/include/gmssl/md5.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/include/gmssl/oid.h b/include/gmssl/oid.h index 8b3390da..a3f1e271 100644 --- a/include/gmssl/oid.h +++ b/include/gmssl/oid.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * -OCSPSigning * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ @@ -262,6 +230,25 @@ enum { OID_aes, + OID_aes128_cbc, + OID_aes192_cbc, + OID_aes256_cbc, + + OID_ecdsa_with_sha1, + OID_ecdsa_with_sha224, + OID_ecdsa_with_sha256, + OID_ecdsa_with_sha384, + OID_ecdsa_with_sha512, + + OID_rsasign_with_sha1, + OID_rsasign_with_sha224, + OID_rsasign_with_sha256, + OID_rsasign_with_sha384, + OID_rsasign_with_sha512, + + OID_rsa_encryption, + OID_rsaes_oaep, + }; diff --git a/include/gmssl/pbkdf2.h b/include/gmssl/pbkdf2.h index 01a17443..c5d85438 100644 --- a/include/gmssl/pbkdf2.h +++ b/include/gmssl/pbkdf2.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_PBKDF2_H diff --git a/include/gmssl/pem.h b/include/gmssl/pem.h index 940f0f32..c40e4a27 100644 --- a/include/gmssl/pem.h +++ b/include/gmssl/pem.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_PEM_H diff --git a/include/gmssl/pkcs8.h b/include/gmssl/pkcs8.h index 07b56a91..004aa3db 100644 --- a/include/gmssl/pkcs8.h +++ b/include/gmssl/pkcs8.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_PKCS8_H diff --git a/include/gmssl/rand.h b/include/gmssl/rand.h index 8a27f3dd..c97f7539 100644 --- a/include/gmssl/rand.h +++ b/include/gmssl/rand.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_RAND_H diff --git a/include/gmssl/rc4.h b/include/gmssl/rc4.h index 5bffb479..e0fe232d 100644 --- a/include/gmssl/rc4.h +++ b/include/gmssl/rc4.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/include/gmssl/sha1.h b/include/gmssl/sha1.h old mode 100755 new mode 100644 index 9dab2470..7009c922 --- a/include/gmssl/sha1.h +++ b/include/gmssl/sha1.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_SHA1_H diff --git a/include/gmssl/sha2.h b/include/gmssl/sha2.h old mode 100755 new mode 100644 index eb2ecfb3..02ced464 --- a/include/gmssl/sha2.h +++ b/include/gmssl/sha2.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/include/gmssl/sha3.h b/include/gmssl/sha3.h index 0497aec6..2aee84c0 100644 --- a/include/gmssl/sha3.h +++ b/include/gmssl/sha3.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/include/gmssl/sm2.h b/include/gmssl/sm2.h index e8df7f92..33998f12 100644 --- a/include/gmssl/sm2.h +++ b/include/gmssl/sm2.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ @@ -100,6 +68,7 @@ int sm2_private_key_to_pem(const SM2_KEY *key, FILE *fp); int sm2_private_key_from_der(SM2_KEY *key, const uint8_t **in, size_t *inlen); int sm2_private_key_from_pem(SM2_KEY *key, FILE *fp); + // AlgorithmIdentifier int sm2_public_key_algor_to_der(uint8_t **out, size_t *outlen); int sm2_public_key_algor_from_der(const uint8_t **in, size_t *inlen); diff --git a/include/gmssl/sm3.h b/include/gmssl/sm3.h old mode 100755 new mode 100644 index aa2b3dca..8c8cbcc8 --- a/include/gmssl/sm3.h +++ b/include/gmssl/sm3.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_SM3_H diff --git a/include/gmssl/sm4.h b/include/gmssl/sm4.h index 833d46cf..f689c87c 100644 --- a/include/gmssl/sm4.h +++ b/include/gmssl/sm4.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_SM4_H @@ -64,7 +32,7 @@ extern "C" { #define SM4_BLOCK_SIZE (16) #define SM4_NUM_ROUNDS (32) - +// TODO: 增加一个flag标注用于加密还是解密,使用时用assert检查这个flag typedef struct { uint32_t rk[SM4_NUM_ROUNDS]; } SM4_KEY; diff --git a/include/gmssl/sm9.h b/include/gmssl/sm9.h index c4a3fd2b..c6fdbe3e 100644 --- a/include/gmssl/sm9.h +++ b/include/gmssl/sm9.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2016 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_SM9_H diff --git a/include/gmssl/tls.h b/include/gmssl/tls.h index 5e63bf49..cd1428e7 100644 --- a/include/gmssl/tls.h +++ b/include/gmssl/tls.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/include/gmssl/version.h b/include/gmssl/version.h new file mode 100644 index 00000000..32906f98 --- /dev/null +++ b/include/gmssl/version.h @@ -0,0 +1,41 @@ +<<<<<<< HEAD:include/gmssl/version.h +/* + * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +======= +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. +>>>>>>> 5fc13a8aefa3fb395f32927e35dda4210a3c1a23:tools/sm2gen.c + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef GMSSL_VERSION_H +#define GMSSL_VERSION_H + + + + +#ifdef __cplusplus +extern "C" { +#endif + + +const char *gmssl_version(void); + + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/include/gmssl/x509.h b/include/gmssl/x509.h index f3c86ae4..ad6f8e28 100644 --- a/include/gmssl/x509.h +++ b/include/gmssl/x509.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_X509_H @@ -168,38 +136,36 @@ AlgorithmIdentifier ::= SEQUENCE { 当 algorithm 为 ECDSA/SM2 时,parameters 为空 当 algorithm 为 RSA 时,parameters 为 ASN1_NULL 对象 */ -int x509_signature_algor_to_der(int algor, uint8_t **out, size_t *outlen); - -int x509_signature_algor_from_der( - int *algor, uint32_t algor_nodes[32], size_t *algor_nodes_count, - const uint8_t **in, size_t *inlen); const char *x509_digest_algor_name(int algor); - -int x509_digest_algor_to_der(int oid, uint8_t **out, size_t *outlen); -int x509_digest_algor_from_der(int *oid, uint32_t *nodes, size_t *nodes_count, +int x509_digest_algor_from_name(const char *name); +int x509_digest_algor_to_der(int algor, uint8_t **out, size_t *outlen); +int x509_digest_algor_from_der(int *algor, uint32_t *nodes, size_t *nodes_count, const uint8_t **in, size_t *inlen); const char *x509_encryption_algor_name(int algor); - -int x509_encryption_algor_to_der(int cipher, const uint8_t *iv, size_t ivlen, +int x509_encryption_algor_from_name(const char *name); +int x509_encryption_algor_to_der(int algor, const uint8_t *iv, size_t ivlen, uint8_t **out, size_t *outlen); - - - -int x509_encryption_algor_from_der( - int *algor, uint32_t algor_nodes[32], size_t *algor_nodes_count, +int x509_encryption_algor_from_der(int *algor, uint32_t *nodes, size_t *nodes_count, const uint8_t **iv, size_t *ivlen, const uint8_t **in, size_t *inlen); -int x509_public_key_encryption_algor_to_der(int algor, uint8_t **out, size_t *outlen); +const char *x509_signature_algor_name(int algor); +int x509_signature_algor_from_name(const char *name); +int x509_signature_algor_to_der(int algor, uint8_t **out, size_t *outlen); +int x509_signature_algor_from_der(int *algor, uint32_t *nodes, size_t *nodes_count, + const uint8_t **in, size_t *inlen); -int x509_public_key_encryption_algor_from_der(int *algor, - uint32_t *nodes, size_t *nodes_count, +const char *x509_public_key_encryption_algor_name(int algor); +int x509_public_key_encryption_algor_from_name(const char *name); +int x509_public_key_encryption_algor_to_der(int algor, uint8_t **out, size_t *outlen); +int x509_public_key_encryption_algor_from_der(int *algor, uint32_t *nodes, size_t *nodes_count, const uint8_t **params, size_t *params_len, const uint8_t **in, size_t *inlen); + /* SubjectPublicKeyInfo ::= SEQUENCE { algorithm AlgorithmIdentifier, @@ -799,8 +765,9 @@ int x509_certificate_get_basic_constraints(const X509_CERTIFICATE *cert, int x509_basic_constraints_print(FILE *fp, const uint8_t *data, size_t datalen, int format, int indent); int x509_key_usage_print(FILE *fp, const uint8_t *data, size_t datalen, int format, int indent); +int x509_ext_key_usage_print(FILE *fp, const uint8_t *data, size_t datalen, int format, int indent); int x509_authority_key_identifier_print(FILE *fp, const uint8_t *data, size_t datalen, int format, int indent); - +int x509_policy_constraints_print(FILE *fp, const uint8_t *p, size_t len, int format, int indent); // Extension 10. Name Constraints @@ -1099,11 +1066,12 @@ typedef struct { int x509_cert_request_info_to_der(const X509_CERT_REQUEST_INFO *a, uint8_t **out, size_t *outlen); int x509_cert_request_info_from_der(X509_CERT_REQUEST_INFO *a, const uint8_t **in, size_t *inlen); +int x509_cert_request_info_print(FILE *fp, const X509_CERT_REQUEST_INFO *a, int format, int indent); typedef struct { X509_CERT_REQUEST_INFO req_info; int signature_algor; - uint8_t signature[128]; + uint8_t signature[SM2_MAX_SIGNATURE_SIZE]; size_t signature_len; } X509_CERT_REQUEST; diff --git a/include/gmssl/zuc.h b/include/gmssl/zuc.h old mode 100755 new mode 100644 index 49b325cd..76853733 --- a/include/gmssl/zuc.h +++ b/include/gmssl/zuc.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_ZUC_H diff --git a/sdf/sdf.h b/sdf/sdf.h index da699665..9ab4f1eb 100644 --- a/sdf/sdf.h +++ b/sdf/sdf.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* * SDF API is a cryptographic API for PCI-E cards defined in standard diff --git a/sdf/sdf_ext.c b/sdf/sdf_ext.c index f28866a4..23b1dd23 100644 --- a/sdf/sdf_ext.c +++ b/sdf/sdf_ext.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2016 - 2017 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/sdf/sdf_ext.h b/sdf/sdf_ext.h index ee05d3db..fba94db5 100644 --- a/sdf/sdf_ext.h +++ b/sdf/sdf_ext.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_SDF_EXT_H diff --git a/sdf/sdf_int.h b/sdf/sdf_int.h index 96b5af02..1f46158f 100644 --- a/sdf/sdf_int.h +++ b/sdf/sdf_int.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef HEADER_SDF_METH_H diff --git a/sdf/sdf_lib.c b/sdf/sdf_lib.c index 588185d1..0ed5e2b4 100644 --- a/sdf/sdf_lib.c +++ b/sdf/sdf_lib.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2016 - 2017 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/sdf/sdf_meth.c b/sdf/sdf_meth.c index c172777c..6caed7de 100644 --- a/sdf/sdf_meth.c +++ b/sdf/sdf_meth.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2016 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include @@ -136,7 +103,7 @@ end: void SDF_METHOD_free(SDF_METHOD *meth) { - if (meth) free(meth->dso); + if (meth) dlclose(meth->dso); free(meth); } diff --git a/sdf/sdf_sansec.c b/sdf/sdf_sansec.c index 67e21e01..27ecc940 100644 --- a/sdf/sdf_sansec.c +++ b/sdf/sdf_sansec.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2016 - 2017 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/sdf/sdf_sansec.h b/sdf/sdf_sansec.h index b7fae475..cefda5bb 100644 --- a/sdf/sdf_sansec.h +++ b/sdf/sdf_sansec.h @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2016 - 2017 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_SDF_SANSEC_H #define GMSSL_SDF_SANSEC_H diff --git a/sdf/sdfutil.c b/sdf/sdfutil.c index 248a3b48..d0007acd 100644 --- a/sdf/sdfutil.c +++ b/sdf/sdfutil.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/sdf/sgd.h b/sdf/sgd.h index 664a86d0..e35f8ffe 100644 --- a/sdf/sgd.h +++ b/sdf/sgd.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2015 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* * this header file is based on the standard GM/T 0006-2012 diff --git a/skf/sgd.h b/skf/sgd.h index 494aa8ca..f63af5bc 100644 --- a/skf/sgd.h +++ b/skf/sgd.h @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2015 - 2016 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* * this header file is based on the standard GM/T 0006-2012 diff --git a/skf/skf.h b/skf/skf.h index dd949083..0611a423 100644 --- a/skf/skf.h +++ b/skf/skf.h @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2015 - 2016 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* This header file is from the official specification with minor * modification. diff --git a/skf/skf_ext.c b/skf/skf_ext.c index fcf30213..b675c3da 100644 --- a/skf/skf_ext.c +++ b/skf/skf_ext.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2019 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/skf/skf_ext.h b/skf/skf_ext.h index 966edc3d..7e5149e1 100644 --- a/skf/skf_ext.h +++ b/skf/skf_ext.h @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2015 - 2016 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef HEADER_GMSKF_H diff --git a/skf/skf_int.h b/skf/skf_int.h index 30023664..fae55ce3 100644 --- a/skf/skf_int.h +++ b/skf/skf_int.h @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef HEADER_SKF_INT_H diff --git a/skf/skf_lib.c b/skf/skf_lib.c index 005f2441..07725a76 100644 --- a/skf/skf_lib.c +++ b/skf/skf_lib.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/skf/skf_meth.c b/skf/skf_meth.c index a5fad81f..e1face84 100644 --- a/skf/skf_meth.c +++ b/skf/skf_meth.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/skf/skf_prn.c b/skf/skf_prn.c index f61bafa5..f0e220c6 100644 --- a/skf/skf_prn.c +++ b/skf/skf_prn.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2019 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/skf/skf_wisec.c b/skf/skf_wisec.c index 8796c3d6..7b657a6a 100644 --- a/skf/skf_wisec.c +++ b/skf/skf_wisec.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2016 - 2017 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/skf/skf_wisec.h b/skf/skf_wisec.h index ddbcae61..9406effc 100644 --- a/skf/skf_wisec.h +++ b/skf/skf_wisec.h @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2016 - 2017 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef HEADER_SKF_WISEC_H diff --git a/skf/skfutil.c b/skf/skfutil.c index 2468dc12..2df9b0c7 100644 --- a/skf/skfutil.c +++ b/skf/skfutil.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2019 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/aes.c b/src/aes.c index 31bfd866..91e777db 100644 --- a/src/aes.c +++ b/src/aes.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/aes_modes.c b/src/aes_modes.c index 70d805a2..bbcf1859 100644 --- a/src/aes_modes.c +++ b/src/aes_modes.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/asn1.c b/src/asn1.c index 970d3437..b0112d50 100644 --- a/src/asn1.c +++ b/src/asn1.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include @@ -163,7 +131,9 @@ int asn1_ia5_string_check(const char *a, size_t alen) ///////////////////////////////////////////////////////////////////////////////////////////// // DER encoding ///////////////////////////////////////////////////////////////////////////////////////////// -// 这组函数不对输入进行检查 +// 这组函数不对输入进行检查 +// 还是检查报错比较方便,这样调用的函数更容易实现 +// asn.1编解码不考虑效率的问题 void asn1_tag_to_der(int tag, uint8_t **out, size_t *outlen) { @@ -211,7 +181,12 @@ void asn1_data_to_der(const uint8_t *data, size_t datalen, uint8_t **out, size_t int asn1_tag_from_der(int tag, const uint8_t **in, size_t *inlen) { - if (*inlen == 0 || **in != tag) { + if (*inlen == 0) { + //error_print_msg("inlen = %zu\n", *inlen); + return 0; + } + if (**in != tag) { + //error_print_msg("tag get %d instead of %d\n", **in, tag); return 0; } (*in)++; @@ -229,12 +204,14 @@ int asn1_length_from_der(size_t *plen, const uint8_t **pin, size_t *pinlen) return -1; } + if (*in < 128) { len = *in++; inlen--; } else { uint8_t buf[4] = {0}; int nbytes = *in++ & 0x7f; + //error_print_msg("nbytes = %d\n", nbytes); if (nbytes < 1 || nbytes > 4) { error_print(); @@ -252,7 +229,8 @@ int asn1_length_from_der(size_t *plen, const uint8_t **pin, size_t *pinlen) } if (inlen < len) { - error_print(); + error_print_msg("inlen = %zu\n", *pinlen); + error_print_msg("length = %zu, left = %zu\n", len, inlen); return -1; } @@ -285,18 +263,18 @@ int asn1_header_to_der(int tag, size_t len, uint8_t **out, size_t *outlen) return 1; } + // If data == NULL, out should not be NULL -// 这个实现是不支持OPTIONAL的, +// 这个实现是不支持OPTIONAL的 int asn1_type_to_der(int tag, const uint8_t *data, size_t datalen, uint8_t **out, size_t *outlen) { - if (data == NULL && datalen == 0 && out) { + // 针对IMPLICIT, OPTIONAL + if (data == NULL && datalen == 0) { return 0; } - if ((!data && out) || datalen >= INT_MAX || (out && !(*out)) || !outlen) { - error_print(); - return -1; - } + // FIXME: asn1_tag,length,data_to_der这几个函数增加错误检查 + // 检查这几个函数的返回值 asn1_tag_to_der(tag, out, outlen); asn1_length_to_der(datalen, out, outlen); asn1_data_to_der(data, datalen, out, outlen); @@ -307,8 +285,11 @@ int asn1_type_to_der(int tag, const uint8_t *data, size_t datalen, uint8_t **out int asn1_type_from_der(int tag, const uint8_t **data, size_t *datalen, const uint8_t **in, size_t *inlen) { int ret; + *data = NULL; + *datalen = 0; if ((ret = asn1_tag_from_der(tag, in, inlen)) != 1) { if (ret < 0) error_print(); + //if (ret == 0) error_print(); return ret; } if (asn1_length_from_der(datalen, in, inlen) != 1 @@ -749,18 +730,26 @@ int asn1_bit_string_from_der_ex(int tag, const uint8_t **bits, size_t *nbits, co int unused_bits; if (!bits || !nbits || !pin || !(*pin) || !pinlen) { + error_print(); return -1; } + + // FIXME: 其他函数可能存在类似情况 + *bits = NULL; + *nbits = 0; + if (inlen-- < 1 || *in++ != tag) { return 0; } if (asn1_length_from_der(&len, &in, &inlen) != 1 || len <= 0) { + error_print(); return -1; } unused_bits = *in; if (unused_bits > 8 || (len == 1 && unused_bits > 0)) { + error_print(); return -1; } @@ -815,6 +804,7 @@ int asn1_null_from_der(const uint8_t **in, size_t *inlen) return 1; } +// FIXME:这个函数应该最终取消返回oid int asn1_object_identifier_from_der_ex(int tag, int *oid, uint32_t nodes[32], size_t *nodes_count, const uint8_t **pin, size_t *pinlen) { @@ -822,7 +812,7 @@ int asn1_object_identifier_from_der_ex(int tag, int *oid, uint32_t nodes[32], si size_t inlen = *pinlen; size_t len; - if (!oid || !nodes || !nodes_count || !pin || !(*pin) || !pinlen) { + if (!nodes || !nodes_count || !pin || !(*pin) || !pinlen) { error_print(); return -1; } @@ -841,7 +831,9 @@ int asn1_object_identifier_from_der_ex(int tag, int *oid, uint32_t nodes[32], si error_print(); return -1; } - *oid = asn1_oid_from_octets(in, len); + if (oid) { + *oid = asn1_oid_from_octets(in, len); + } *pin = in + len; *pinlen = inlen - len; return 1; @@ -1040,3 +1032,12 @@ int asn1_check(int expr) error_print(); return -1; } + +int asn1_length_is_zero(size_t len) +{ + if (len) { + error_print(); + return 0; + } + return 1; +} diff --git a/src/block_cipher.c b/src/block_cipher.c index 042d61de..f02e99b1 100644 --- a/src/block_cipher.c +++ b/src/block_cipher.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/chacha20.c b/src/chacha20.c index 5b3cccce..85f82883 100644 --- a/src/chacha20.c +++ b/src/chacha20.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/cms.c b/src/cms.c index fc0fa00a..e4ec5f3b 100644 --- a/src/cms.c +++ b/src/cms.c @@ -1,52 +1,25 @@ -/* +<<<<<<< HEAD +/* * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +======= +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. +>>>>>>> 5fc13a8aefa3fb395f32927e35dda4210a3c1a23 * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - +#include #include #include #include @@ -59,13 +32,34 @@ #include #include +// 这个是干什么用的? +int find_cert(X509_CERTIFICATE *cert, + const uint8_t *certs, size_t certslen, + const X509_NAME *issuer, const uint8_t *serial_number, size_t serial_number_len) +{ + + while (certslen) { + if (x509_certificate_from_der(cert, &certs, &certslen) != 1) { + error_print(); + return -1; + } + + if (x509_name_equ(issuer, &cert->tbs_certificate.issuer) + && serial_number_len == cert->tbs_certificate.serial_number_len + && memcmp(serial_number, cert->tbs_certificate.serial_number, serial_number_len) == 0) { + return 1; + } + } + + return 0; +} + + /* data ::= OCTET STRING */ - - int cms_data_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent) { const uint8_t *data; @@ -84,7 +78,6 @@ int cms_data_print(FILE *fp, const uint8_t *a, size_t alen, int format, int inde } - /* EncryptedContentInfo ::= SEQUENCE { contentType OBJECT IDENTIFIER, @@ -144,7 +137,7 @@ int cms_enced_content_info_from_der(int *content_type, || x509_encryption_algor_from_der(enc_algor, nodes, &nodes_count, enc_iv, enc_iv_len, &data, &datalen) != 1 || asn1_implicit_octet_string_from_der(0, enced_content, enced_content_len, &data, &datalen) < 0 || asn1_implicit_octet_string_from_der(1, shared_info1, shared_info1_len, &data, &datalen) < 0 - || asn1_implicit_octet_string_from_der(1, shared_info2, shared_info2_len, &data, &datalen) < 0 + || asn1_implicit_octet_string_from_der(2, shared_info2, shared_info2_len, &data, &datalen) < 0 || asn1_check(datalen == 0) != 1) { error_print(); return -1; @@ -152,39 +145,24 @@ int cms_enced_content_info_from_der(int *content_type, return 1; } -int cms_enced_content_info_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent) +int cms_enced_content_info_print(FILE *fp, + int content_type, + int enc_algor, const uint8_t *enc_iv, size_t enc_iv_len, + const uint8_t *enced_content, size_t enced_content_len, + const uint8_t *shared_info1, size_t shared_info1_len, + const uint8_t *shared_info2, size_t shared_info2_len, + int format, int indent) { - int ret; - int content_type = 0; - int enc_algor = 0; - const uint8_t *enc_iv = NULL; - const uint8_t *enced_content = NULL; - const uint8_t *shared_info1 = NULL; - const uint8_t *shared_info2 = NULL; - size_t enc_iv_len = 0; - size_t enced_content_len = 0; - size_t shared_info1_len = 0; - size_t shared_info2_len = 0; - format_print(fp, format, indent, "EncryptedContentInfo:\n"); indent += 4; - if ((ret = cms_enced_content_info_from_der(&content_type, - &enc_algor, &enc_iv, &enc_iv_len, - &enced_content, &enced_content_len, - &shared_info1, &shared_info1_len, - &shared_info2, &shared_info2_len, - &a, &alen)) != 1) { - error_print(); - } - format_print(fp, format, indent, "contentType: %s\n", cms_content_type_name(content_type)); format_print(fp, format, indent, "contentEncryptionAlgorithm: %s\n", x509_encryption_algor_name(enc_algor)); format_bytes(fp, format, indent + 4, "iv: ", enc_iv, enc_iv_len); format_bytes(fp, format, indent, "encryptedContent: ", enced_content, enced_content_len); format_bytes(fp, format, indent, "sharedInfo1: ", shared_info1, shared_info1_len); format_bytes(fp, format, indent, "sharedInfo2: ", shared_info2, shared_info2_len); - return ret; + return 1; } int cms_enced_content_info_encrypt_to_der(const SM4_KEY *sm4_key, const uint8_t iv[16], @@ -196,15 +174,11 @@ int cms_enced_content_info_encrypt_to_der(const SM4_KEY *sm4_key, const uint8_t uint8_t enced_content[content_len + 256]; size_t enced_content_len; - error_print_msg("*outlen = %zu\n", *outlen); - if (sm4_cbc_padding_encrypt(sm4_key, iv, content, content_len, enced_content, &enced_content_len) != 1) { error_print(); return -1; } - error_print_msg("content_len = %zu, out = %zu\n", content_len, enced_content_len); - if (cms_enced_content_info_to_der(OID_sm4_cbc, iv, 16, content_type, enced_content, enced_content_len, shared_info1, shared_info1_len, @@ -213,7 +187,6 @@ int cms_enced_content_info_encrypt_to_der(const SM4_KEY *sm4_key, const uint8_t error_print(); return -1; } - error_print_msg("*outlen = %zu\n\n", *outlen); return 1; } @@ -247,14 +220,12 @@ int cms_enced_content_info_decrypt_from_der(const SM4_KEY *key, return 1; } - - /* EncryptedData ::= SEQUENCE { version INTEGER (1), encryptedContentInfo EncryptedContentInfo ::= SEQUENCE { contentType OBJECT IDENTIFIER, - contentEncryptionAlgorithm AlgorithmIdentifier, // 包含IV + contentEncryptionAlgorithm AlgorithmIdentifier, // 包含参数IV encryptedContent [0] IMPLICIT OCTET STRING OPTIONAL, sharedInfo1 [1] IMPLICIT OCTET STRING OPTIONAL, sharedInfo2 [2] IMPLICIT OCTET STRING OPTIONAL, @@ -278,7 +249,6 @@ int cms_encrypted_data_to_der(int enc_algor, const uint8_t *enc_iv, size_t enc_i error_print(); return -1; } - error_print_msg("len = %zu\n", len); if (asn1_sequence_header_to_der(len, out, outlen) != 1 || asn1_int_to_der(CMS_version, out, outlen) != 1 || cms_enced_content_info_to_der(enc_algor, enc_iv, enc_iv_len, @@ -303,11 +273,9 @@ int cms_encrypted_data_decrypt_from_der(const SM4_KEY *key, size_t datalen; int version; - format_bytes(stderr, 0, 0, "in = ", *in, *inlen); - error_print_msg("len =%zu\n", *inlen); - if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { if (ret < 0) error_print(); + else error_print(); return ret; } if (asn1_int_from_der(&version, &data, &datalen) != 1 @@ -328,55 +296,6 @@ int cms_encrypted_data_decrypt_from_der(const SM4_KEY *key, return 1; } -int cms_encrypted_data_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent) -{ - const uint8_t *data; - size_t datalen; - int version; - const uint8_t *enced_content_info; - size_t enced_content_info_len; - const uint8_t *p; - size_t len; - - if (asn1_sequence_from_der(&data, &datalen, &a, &alen) != 1) { - error_print(); - return -1; - } - - format_print(fp, format, indent, "EncryptedData\n"); - indent += 4; - - if (asn1_int_from_der(&version, &data, &datalen) != 1) { - error_print(); - return -1; - } - format_print(fp, format, indent, "Version : %d\n", version); - - enced_content_info = data; - if (asn1_sequence_from_der(&p, &len, &data, &datalen) != 1) { - error_print(); - return -1; - } - enced_content_info_len = data - enced_content_info; - if (cms_enced_content_info_print(fp, enced_content_info, enced_content_info_len, - format, indent) != 1) { - error_print(); - return -1; - } - - if (datalen) { - error_print(); - format_print(fp, format, indent, "ErrorLeft %zu bytes\n", datalen); - } - if (alen) { - error_print(); - format_print(fp, format, indent, "ErrorLeft %zu bytes\n", alen); - } - - return 1; -} - - int cms_encrypted_data_from_der(int *content_type, int *enc_algor, const uint8_t **enc_iv, size_t *enc_iv_len, const uint8_t **enced_content, size_t *enced_content_len, @@ -411,6 +330,49 @@ int cms_encrypted_data_from_der(int *content_type, return 1; } +int cms_encrypted_data_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent) +{ + int version; + int content_type; + int enc_algor; + const uint8_t *enc_iv; + size_t enc_iv_len; + const uint8_t *enced_content; + size_t enced_content_len; + const uint8_t *shared_info1; + size_t shared_info1_len; + const uint8_t *shared_info2; + size_t shared_info2_len; + + if (cms_encrypted_data_from_der( + &content_type, + &enc_algor, &enc_iv, &enc_iv_len, + &enced_content, &enced_content_len, + &shared_info1, &shared_info1_len, + &shared_info2, &shared_info2_len, + &a, &alen) != 1) { + error_print(); + return -1; + } + + format_print(fp, format, indent, "EncryptedData:\n"); + indent += 4; + format_print(fp, format, indent, "Version : %d\n", version); + cms_enced_content_info_print(fp, + content_type, + enc_algor, enc_iv, enc_iv_len, + enced_content, enced_content_len, + shared_info1, shared_info1_len, + shared_info2, shared_info2_len, + format, indent); + + if (alen) { + error_print(); + return -1; + } + return 1; +} + int cms_encrypted_data_encrypt_to_der(const SM4_KEY *sm4_key, const uint8_t iv[16], int content_type, const uint8_t *content, size_t content_len, const uint8_t *shared_info1, size_t shared_info1_len, @@ -419,8 +381,6 @@ int cms_encrypted_data_encrypt_to_der(const SM4_KEY *sm4_key, const uint8_t iv[1 { size_t len = 0; - error_print_msg("outlen = %zu\n", *outlen); - if (asn1_int_to_der(CMS_version, NULL, &len) != 1 || cms_enced_content_info_encrypt_to_der(sm4_key, iv, content_type, content, content_len, @@ -430,7 +390,7 @@ int cms_encrypted_data_encrypt_to_der(const SM4_KEY *sm4_key, const uint8_t iv[1 error_print(); return -1; } - error_print_msg("len = %zu\n", len); + if (asn1_sequence_header_to_der(len, out, outlen) != 1 || asn1_int_to_der(CMS_version, out, outlen) != 1 || cms_enced_content_info_encrypt_to_der(sm4_key, iv, @@ -441,7 +401,6 @@ int cms_encrypted_data_encrypt_to_der(const SM4_KEY *sm4_key, const uint8_t iv[1 error_print(); return -1; } - error_print_msg("outlen = %zu\n\n", *outlen); return 1; } @@ -455,29 +414,6 @@ KeyAgreementInfo ::= SEQUENCE { } */ -int cms_key_agreement_info_from_der(SM2_KEY *pub_key, X509_CERTIFICATE *cert, - const uint8_t **user_id, size_t *user_id_len, const uint8_t **in, size_t *inlen) -{ - int ret; - const uint8_t *data; - size_t datalen; - int version; - - if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { - if (ret < 0) error_print(); - return ret; - } - if (asn1_int_from_der(&version, &data, &datalen) != 1 - || sm2_public_key_info_from_der(pub_key, &data, &datalen) != 1 - || x509_certificate_from_der(cert, &data, &datalen) != 1 - || asn1_octet_string_from_der(user_id, user_id_len, &data, &datalen) != 1 - || datalen > 0) { - error_print(); - return -1; - } - return 1; -} - int cms_key_agreement_info_to_der(const SM2_KEY *pub_key, const X509_CERTIFICATE *cert, const uint8_t *user_id, size_t user_id_len, uint8_t **out, size_t *outlen) { @@ -501,7 +437,55 @@ int cms_key_agreement_info_to_der(const SM2_KEY *pub_key, const X509_CERTIFICATE return 1; } +int cms_key_agreement_info_from_der(SM2_KEY *pub_key, X509_CERTIFICATE *cert, + const uint8_t **user_id, size_t *user_id_len, const uint8_t **in, size_t *inlen) +{ + int ret; + const uint8_t *data; + size_t datalen; + int version; + if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { + if (ret < 0) error_print(); + return ret; + } + if (asn1_int_from_der(&version, &data, &datalen) != 1 + || sm2_public_key_info_from_der(pub_key, &data, &datalen) != 1 + || x509_certificate_from_der(cert, &data, &datalen) != 1 + || asn1_octet_string_from_der(user_id, user_id_len, &data, &datalen) != 1 + || asn1_length_is_zero(datalen) != 1) { + error_print(); + return -1; + } + return 1; +} + +int cms_key_agreement_info_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent) +{ + SM2_KEY pub_key; + X509_CERTIFICATE cert; + const uint8_t *user_id; + size_t user_id_len; + + if (cms_key_agreement_info_from_der(&pub_key, &cert, &user_id, &user_id_len, &a, &alen) != 1) { + error_print(); + return -1; + } + format_print(fp, format, indent, "KeyAgreementInfo :\n"); + indent += 4; + format_print(fp, format, indent, "Version : 1\n"); + format_print(fp, format, indent, "tempPublicKeyR "); + sm2_key_print(fp, &pub_key, format, indent + 4); + format_print(fp, format, indent, "userCertificate "); + x509_certificate_print(fp, &cert, format, indent + 4); + format_bytes(fp, format, indent, "userID : ", user_id, user_id_len); + + if (alen) { + error_print(); + return -1; + } + return 1; +} /* IssuerAndSerialNumber ::= SEQUENCE { @@ -510,7 +494,6 @@ IssuerAndSerialNumber ::= SEQUENCE { } */ - int cms_issuer_and_serial_number_from_certificate(const X509_NAME **issuer, const uint8_t **serial_number, size_t *serial_number_len, const X509_CERTIFICATE *cert) @@ -568,48 +551,42 @@ int cms_issuer_and_serial_number_from_der(X509_NAME *issuer, return 1; } -// 打印的使用场景可能是没有header的 -int cms_issuer_and_serial_number_print(FILE *fp, const uint8_t *in, size_t inlen, int format, int indent) +int cms_issuer_and_serial_number_print(FILE *fp, + const X509_NAME *issuer, + const uint8_t *serial_number, size_t serial_number_len, + int format, int indent) { - /* - int ret; - const uint8_t *data; - size_t datalen; - X509_NAME issuer; - const uint8_t *serial_number; - size_t serial_number_len; - - if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { - if (ret < 0) error_print(); - return ret; - } - format_print(fp, format, indent, "IssuerAndSerialNumber\n"); + format_print(fp, format, indent, "IssuerAndSerialNumber:\n"); indent += 4; - - if (x509_name_from_der(&issuer, &data, &datalen) != 1) goto bad; - format_print(fp, format, indent, "issuer :\n"); - x509_name_print(fp, &issuer, format, indent); - - if (asn1_integer_from_der(&serial_number, &serial_number_len, &data, &datalen) != 1) goto bad; - format_bytes(fp, format, indent, "serialNumber : ", serial_number, serial_number_len); + format_print(fp, format, indent, "issuer:\n"); + x509_name_print(fp, issuer, format, indent + 4); + format_bytes(fp, format, indent, "serialNumber: ", serial_number, serial_number_len); return 1; -bad: - error_print(); - */ - return -1; } - - /* RecipientInfo ::= SEQUENCE { version INTEGER (1), issuerAndSerialNumber IssuerAndSerialNumber, keyEncryptionAlgorithm AlgorithmIdentifier, - encryptedKey OCTET STRING + encryptedKey OCTET STRING // 包含SM2Ciphertext的DER编码,变长数据 } */ +int cms_recipient_info_from_x509_certificate( + const SM2_KEY **key, + const X509_NAME **issuer, + const uint8_t **serial_number, size_t *serial_number_len, + const X509_CERTIFICATE *cert) +{ + *issuer = &cert->tbs_certificate.issuer; + *serial_number = &cert->tbs_certificate.serial_number[0]; + *serial_number_len = cert->tbs_certificate.serial_number_len; + *key = &cert->tbs_certificate.subject_public_key_info.sm2_key; + return 1; +} + + int cms_recipient_info_to_der(const X509_NAME *issuer, const uint8_t *serial_number, size_t serial_number_len, const uint8_t *enced_key, size_t enced_key_len, @@ -635,46 +612,68 @@ int cms_recipient_info_to_der(const X509_NAME *issuer, return 1; } -int cms_recipient_info_from_der(X509_NAME *issuer, +int cms_recipient_info_from_der( + int *version, + X509_NAME *issuer, const uint8_t **serial_number, size_t *serial_number_len, + int *pke_algor, const uint8_t **params, size_t *paramslen, const uint8_t **enced_key, size_t *enced_key_len, const uint8_t **in, size_t *inlen) { int ret; const uint8_t *data; size_t datalen; - int version; - int pke_algor; uint32_t pke_algor_nodes[32]; size_t pke_algor_nodes_count; - const uint8_t *iv; - size_t ivlen; if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { if (ret < 0) error_print(); return ret; } - if (asn1_int_from_der(&version, &data, &datalen) != 1 - || cms_issuer_and_serial_number_from_der(issuer, serial_number, serial_number_len, &data, &datalen) != 1 - || x509_public_key_encryption_algor_from_der(&pke_algor, pke_algor_nodes, &pke_algor_nodes_count, &iv, &ivlen, &data, &datalen) != 1 - || asn1_octet_string_from_der(enced_key, enced_key_len, &data, &datalen) != 1 - || datalen) { + if (asn1_int_from_der(version, &data, &datalen) != 1) { error_print(); return -1; } - if (version != CMS_version) { + if (cms_issuer_and_serial_number_from_der(issuer, serial_number, serial_number_len, &data, &datalen) != 1 + || x509_public_key_encryption_algor_from_der(pke_algor, pke_algor_nodes, &pke_algor_nodes_count, params, paramslen, &data, &datalen) != 1) { + error_print(); + return -1; + } + if (asn1_octet_string_from_der(enced_key, enced_key_len, &data, &datalen) != 1 + || asn1_length_is_zero(datalen) != 1) { + error_print(); + return -1; + } + if (*version != CMS_version) { error_print(); return -1; } - return -1; + return 1; } -int cms_recipient_info_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent) +int cms_recipient_info_print(FILE *fp, + int version, + const X509_NAME *issuer, const uint8_t *serial_number, size_t serial_number_len, + int pke_algor, const uint8_t *params, size_t paramslen, + const uint8_t *enced_key, size_t enced_key_len, + int format, int indent) { - return -1; + format_print(fp, format, indent, "RecipientInfo:\n"); + indent += 4; + format_print(fp, format, indent, "Version: %d\n", version); + cms_issuer_and_serial_number_print(fp, issuer, serial_number, serial_number_len, format, indent); + format_print(fp, format, indent, "KeyEncryptionAlgorithm: %s\n", x509_public_key_encryption_algor_name(pke_algor)); + /* + if (params && paramslen) { + format_bytes(fp, format, indent + 4, "parameters: ", params, paramslen); + } + */ + format_bytes(fp, format, indent, "EncryptedKey: ", enced_key, enced_key_len); + return 1; } + int cms_recipient_info_encrypt_to_der(const SM2_KEY *sm2_key, const X509_NAME *issuer, const uint8_t *serial_number, size_t serial_number_len, const uint8_t *key, size_t keylen, @@ -697,26 +696,59 @@ int cms_recipient_info_decrypt_from_der(const SM2_KEY *sm2_key, uint8_t *key, size_t *keylen, const uint8_t **in, size_t *inlen) { - /* - if (cms_recipient_info_from_der(issuer, serial_number, serial_number_len, - &enced_key, &enced_key_len, &rcpt_info, &rcpt_info_len) != 1 - || rcpt_info_len) { + int ret; + int version; + int pke_algor; + const uint8_t *pke_params; + size_t pke_params_len; + const uint8_t *enced_key; + size_t enced_key_len; + + if ((ret = cms_recipient_info_from_der(&version, + issuer, serial_number, serial_number_len, + &pke_algor, &pke_params, &pke_params_len, + &enced_key, &enced_key_len, + in, inlen)) != 1 + || asn1_check(version == CMS_version) != 1 + || asn1_check(pke_algor == OID_sm2encrypt) != 1) { + if (ret < 0) error_print(); + return ret; + } + if (sm2_decrypt(sm2_key, enced_key, enced_key_len, key, keylen) != 1) { error_print(); return -1; } - sm2_decrypt(sm2_key, enced_key, enced_key_len, key, keylen); - */ - return -1; + return 1; } - /* EnvelopedData ::= SEQUENCE { version INTEGER (1), recipientInfos SET OF RecipientInfo, - encryptedContentInfo EncryptedContentInfo + encryptedContentInfo EncryptedContentInfo ::= SEQUENCE { + contentType OBJECT IDENTIFIER, + contentEncryptionAlgorithm AlgorithmIdentifier, // 包含IV + encryptedContent [0] IMPLICIT OCTET STRING OPTIONAL, + sharedInfo1 [1] IMPLICIT OCTET STRING OPTIONAL, + sharedInfo2 [2] IMPLICIT OCTET STRING OPTIONAL, + } } + + +ContentInfo ::= SEQUENCE { + contentType OBJECT IDENTIFIER, + content [0] EXPLICIT ANY OPTIONAL + +这里到底加密的是什么? + +"content octets of the definite-length BER encoding of the the content field of + ContentInfo value" + +ContentInfo.content 是一个封装在explicit [0]中的一个完整的TLV的值 +要加密的就是这个值(可能是另外一个ContentInfo) +只有当这个ContentInfo类型是data时,只是用来处理数据 + */ // 这个函数几乎是没有用的,因为我们用一个整体的函数去调用这个功能 @@ -745,6 +777,7 @@ int cms_enveloped_data_from_der(const uint8_t **rcpt_infos, size_t *rcpt_infos_l size_t datalen; int version; + if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { if (ret < 0) error_print(); return ret; @@ -764,9 +797,10 @@ int cms_enveloped_data_from_der(const uint8_t **rcpt_infos, size_t *rcpt_infos_l return 1; } + +// 不做解密,打印加密的RecipientInfo和EncryptedContentInfo int cms_enveloped_data_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent) { - const uint8_t *rcpt_infos; size_t rcpt_infos_len; int content_type; @@ -777,7 +811,6 @@ int cms_enveloped_data_print(FILE *fp, const uint8_t *a, size_t alen, int format const uint8_t *shared_info2; size_t enc_iv_len, enced_content_len, shared_info1_len, shared_info2_len; - if (cms_enveloped_data_from_der(&rcpt_infos, &rcpt_infos_len, &content_type, &enc_algor, &enc_iv, &enc_iv_len, &enced_content, &enced_content_len, @@ -788,12 +821,52 @@ int cms_enveloped_data_print(FILE *fp, const uint8_t *a, size_t alen, int format return -1; } - // 这意味着我们在对应 + format_print(fp, format, indent, "EnvelopedData:\n"); + indent += 4; + format_print(fp, format, indent, "Version: %d\n", CMS_version); - return -1; + format_print(fp, format, indent, "RecipientInfos:\n"); + while (rcpt_infos_len) { + int version; + X509_NAME issuer; + const uint8_t *serial_number; + size_t serial_number_len; + int pke_algor; + const uint8_t *pke_params; + size_t pke_params_len; + const uint8_t *enced_key; + size_t enced_key_len; + + if (cms_recipient_info_from_der( + &version, + &issuer, &serial_number, &serial_number_len, + &pke_algor, &pke_params, &pke_params_len, + &enced_key, &enced_key_len, + &rcpt_infos, &rcpt_infos_len) != 1) { + error_print(); + return -1; + } + cms_recipient_info_print(fp, + version, + &issuer, serial_number, serial_number_len, + pke_algor, pke_params, pke_params_len, + enced_key, enced_key_len, + format, indent + 4); + } + + cms_enced_content_info_print(fp, + content_type, + enc_algor, enc_iv, enc_iv_len, + enced_content, enced_content_len, + shared_info1, shared_info1_len, + shared_info2, shared_info2_len, + format, indent); + + return -1; } +// 这个数据长度为什么不一样? int cms_enveloped_data_encrypt_to_der(const X509_CERTIFICATE *rcpt_certs, size_t rcpt_count, int content_type, const uint8_t *content, size_t content_len, const uint8_t *shared_info1, size_t shared_info1_len, @@ -804,43 +877,42 @@ int cms_enveloped_data_encrypt_to_der(const X509_CERTIFICATE *rcpt_certs, size_t SM4_KEY sm4_key; uint8_t enc_key[16]; uint8_t enc_iv[16]; - uint8_t enced_key[rcpt_count][256 + 16]; - size_t enced_key_len[rcpt_count]; - uint8_t enced_content_info[content_len + 512]; - size_t enced_content_info_len; - size_t i; const SM2_KEY *sm2_key; + const X509_NAME *issuer; + const uint8_t *serial_number; + size_t serial_number_len; size_t rcpt_infos_len = 0; + size_t i; + rand_bytes(enc_key, 16); rand_bytes(enc_iv, 16); - for (i = 0; i < rcpt_count; i++) { - // = x509_certificate_get_public_key(rcpt_certs[i]); - sm2_encrypt(sm2_key, enc_key, 16, enced_key[i], &enced_key_len[i]); - } + + + + /* + 每次生成的密文长度都是不同的,有SM2Ciphertext决定 + 纯数据为 32 + 32 + 32 + 16 + */ for (i = 0; i < rcpt_count; i++) { - // 这个应该改为cms_recipient_info_from_x509 - /* - x509_certificate_get_recipient_info(rcpt_cert, - &issuer, - &serial_number, &serial_number_len, - &sm2_key); + cms_recipient_info_from_x509_certificate(&sm2_key, + &issuer, &serial_number, &serial_number_len, + &rcpt_certs[i]); - */ - /* - cms_recipient_info_encrypt_to_der(issuer, - serial_number, serial_number_len, - enced_key, enced_key_len, + rcpt_infos_len = 0; + + // FIXME: 预先估计的长度是不对的,因为每次SM2密文的长度都是不同的! + cms_recipient_info_encrypt_to_der(sm2_key, + issuer, serial_number, serial_number_len, + enc_key, sizeof(enc_key), NULL, &rcpt_infos_len); - */ + error_print_msg("rcpt_infos_len = %zu\n", rcpt_infos_len); } - - if (asn1_int_to_der(CMS_version, NULL, &len) != 1 || asn1_set_to_der(NULL, rcpt_infos_len, NULL, &len) != 1 || cms_enced_content_info_encrypt_to_der(&sm4_key, enc_iv, @@ -851,27 +923,24 @@ int cms_enveloped_data_encrypt_to_der(const X509_CERTIFICATE *rcpt_certs, size_t error_print(); return -1; } + error_print_msg("len = %zu\n", len); + error_print_msg("outlen = %zu\n", *outlen); if (asn1_sequence_header_to_der(len, out, outlen) != 1 || asn1_int_to_der(CMS_version, out, outlen) != 1 || asn1_set_header_to_der(rcpt_infos_len, out, outlen) != 1) { error_print(); return -1; } - - const X509_NAME *issuer; - const uint8_t *serial_number; - size_t serial_number_len; - for (i = 0; i < rcpt_count; i++) { if (cms_recipient_info_encrypt_to_der(sm2_key, issuer, serial_number, serial_number_len, - enc_key, sizeof(enc_key), out, outlen) != 1) { + enc_key, sizeof(enc_key), + out, outlen) != 1) { error_print(); return -1; } } - if (cms_enced_content_info_encrypt_to_der(&sm4_key, enc_iv, content_type, content, content_len, shared_info1, shared_info1_len, @@ -880,15 +949,24 @@ int cms_enveloped_data_encrypt_to_der(const X509_CERTIFICATE *rcpt_certs, size_t error_print(); return -1; } - + error_print_msg("outlen = %zu\n", *outlen); return 1; } -int cms_enveloped_data_decrypt_from_der(const SM2_KEY *sm2_key, const X509_CERTIFICATE *cert, - const uint8_t *enveloped_data, size_t enveloped_data_len, - int *content_type, uint8_t *content, size_t *content_len) -{ +// 这里我们必须在整个RecipientInfos中找到匹配的,然后才能解密 /* +1. 扫描RecipientInfos,查看是否有和sm2_key, cert匹配的证书 +2. 从找到的RecipientInfo,从加密算法中获取IV,对数据进行私钥解密后得到被加密的对称密钥key +3. 用key, iv对被加密的content进行解密 +*/ +int cms_enveloped_data_decrypt_from_der( + const SM2_KEY *sm2_key, //解密方只有一个私钥,因此不管接收哪来的消息,只能用自己的私钥去尝试解密 + const X509_CERTIFICATE *cert, // 证书用于提供IssuerAndSerialNumber,从RecipientInfos中找到私钥对应的那个 + int *content_type, uint8_t *content, size_t *content_len, + const uint8_t **shared_info1, size_t *shared_info1_len, + const uint8_t **shared_info2, size_t *shared_info2_len, + const uint8_t **in, size_t *inlen) +{ const uint8_t *rcpt_infos; size_t rcpt_infos_len; int enc_algor; @@ -896,22 +974,33 @@ int cms_enveloped_data_decrypt_from_der(const SM2_KEY *sm2_key, const X509_CERTI size_t enc_algor_nodes_count; const uint8_t *enced_content; size_t enced_content_len; - const uint8_t *shared_info1; - size_t shared_info1_len; - const uint8_t *shared_info2; - size_t shared_info2_len; uint8_t enc_key[64]; size_t enc_key_len; const uint8_t *enc_iv; size_t enc_iv_len; + SM4_KEY sm4_key; + + + const X509_NAME *cert_issuer; + const uint8_t *cert_serial; + size_t cert_serial_len; + + if (cms_issuer_and_serial_number_from_certificate(&cert_issuer, + &cert_serial, &cert_serial_len, cert) != 1) { + error_print(); + return -1; + } + + printf("input lenght = %zu\n", *inlen); if (cms_enveloped_data_from_der(&rcpt_infos, &rcpt_infos_len, - content_type, &enc_algor, enc_algor_nodes, &enc_algor_nodes_count, - &enc_iv, &enc_iv_len, - &enced_content, &enced_content_len, &shared_info1, &shared_info1_len, - &shared_info2, &shared_info2_len, &enveloped_data, &enveloped_data_len) != 1 - || enced_content_info_len > 0) { + content_type, &enc_algor, + &enc_iv, &enc_iv_len, + &enced_content, &enced_content_len, + shared_info1, shared_info1_len, + shared_info2, shared_info2_len, + in, inlen) != 1) { error_print(); return -1; } @@ -925,21 +1014,37 @@ int cms_enveloped_data_decrypt_from_der(const SM2_KEY *sm2_key, const X509_CERTI } while (rcpt_infos_len) { + int version; X509_NAME issuer; const uint8_t *serial_number; size_t serial_number_len; + int pke_algor; + const uint8_t *pke_params; + size_t pke_params_len; const uint8_t *enced_key; size_t enced_key_len; - if (cms_recipient_info_from_der(&issuer, &serial_number, &serial_number_len - &enced_key, &enced_key_len, &rcpt_infos, &rcpt_infos_len) != 1) { + if (cms_recipient_info_from_der( + &version, + &issuer, + &serial_number, &serial_number_len, + &pke_algor, &pke_params, &pke_params_len, + &enced_key, &enced_key_len, + &rcpt_infos, &rcpt_infos_len) != 1) { error_print(); return -1; } - if (cms_issuer_and_serial_number_match_certificate(&issuer, - serial_number, serial_number_len, cert) != 1) { - break; + // 这里应该检查一下公钥类型到底对不对 + + + + + if (cert_serial_len != serial_number_len + || memcmp(serial_number, cert_serial, cert_serial_len) + || x509_name_equ(cert_issuer, &issuer) != 1) { + continue; } + if (sm2_decrypt(sm2_key, enced_key, enced_key_len, enc_key, &enc_key_len) != 1) { error_print(); return -1; @@ -947,13 +1052,16 @@ int cms_enveloped_data_decrypt_from_der(const SM2_KEY *sm2_key, const X509_CERTI } sm4_set_decrypt_key(&sm4_key, enc_key); - if (sm4_cbc_paddnig_decrypt(&sm4_key, enc_iv, enced_content, enced_content_len, - content, content_len) != 1) { + if (sm4_cbc_padding_decrypt( + &sm4_key, enc_iv, + enced_content, enced_content_len, + content, content_len) != 1) { error_print(); return -1; } -*/ - return -1; + + + return 1; } @@ -1044,13 +1152,27 @@ int cms_content_info_to_der(int content_type, const uint8_t *content, size_t con { size_t len = 0; - if (cms_content_type_to_der(content_type, NULL, &len) != 1 - || asn1_explicit_to_der(0, content, content_len, NULL, &len) != 1 - || asn1_sequence_header_to_der(len, out, outlen) != 1 - || cms_content_type_to_der(content_type, out, outlen) != 1 - || asn1_explicit_to_der(0, content, content_len, out, outlen) != 1) { - error_print(); - return -1; + if (content_type == CMS_data) { + size_t octets_len = 0; + if (asn1_octet_string_to_der(content, content_len, NULL, &octets_len) != 1 + || cms_content_type_to_der(content_type, NULL, &len) != 1 + || asn1_explicit_to_der(0, NULL, octets_len, NULL, &len) != 1 + || asn1_sequence_header_to_der(len, out, outlen) != 1 + || cms_content_type_to_der(content_type, out, outlen) != 1 + || asn1_explicit_header_to_der(0, octets_len, out, outlen) != 1 + || asn1_octet_string_to_der(content, content_len, out, outlen) != 1) { + error_print(); + return -1; + } + } else { + if (cms_content_type_to_der(content_type, NULL, &len) != 1 + || asn1_explicit_to_der(0, content, content_len, NULL, &len) != 1 + || asn1_sequence_header_to_der(len, out, outlen) != 1 + || cms_content_type_to_der(content_type, out, outlen) != 1 + || asn1_explicit_to_der(0, content, content_len, out, outlen) != 1) { + error_print(); + return -1; + } } return 1; } @@ -1075,7 +1197,6 @@ int cms_content_info_from_der(int *content_type, const uint8_t **content, size_t return 1; } - /* SignerInfo ::= SEQUENCE { version INTEGER (1), @@ -1083,7 +1204,7 @@ SignerInfo ::= SEQUENCE { digestAlgorithm AlgorithmIdentifier, authenticatedAttributes [0] IMPLICIT SET OF Attribute OPTINOAL, digestEncryptionAlgorithm AlgorithmIdentifier, - encryptedDigest OCTET STRING, + encryptedDigest OCTET STRING, // 变长字符串 unauthenticatedAttributes [1] IMPLICIT SET OF Attribute OPTINOAL, } */ @@ -1169,29 +1290,33 @@ int cms_signer_info_from_der(X509_NAME *issuer, return 1; } -int cms_signer_info_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent) +int cms_signer_info_print(FILE *fp, + int version, + const X509_NAME *issuer, const uint8_t *serial_number, size_t serial_number_len, + int digest_algor, const uint8_t *digest_params, size_t digest_params_len, + const uint8_t *authed_attrs, size_t authed_attrs_len, + int sign_algor, const uint8_t *sign_params, size_t sign_params_len, + const uint8_t *sig, size_t siglen, + const uint8_t *unauthed_attrs, size_t unauthed_attrs_len, + int format, int indent) { - /* - int ret; - const uint8_t *data; - size_t datalen; - int version; - X509_NAME issuer; - - if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { - if (ret < 0) error_print(); - return ret; - } format_print(fp, format, indent, "SignerInfo:\n"); indent += 4; - - if (asn1_int_from_der(&version, &data, &datalen) != 1) goto bad; format_print(fp, format, indent, "Version: %d\n", version); + cms_issuer_and_serial_number_print(fp, issuer, serial_number, serial_number_len, format, indent); + format_print(fp, format, indent, "digestAlgorithm: %s\n", x509_digest_algor_name(digest_algor)); - if (cms_issuer_and_serial_number_from_der(&issuer, &serial_number, &serial_number_len, &data, &datalen) != 1) goto bad; - cms_issuer_and_serial_number_print(); // 这个不能这么弄啊! - - */ + if (digest_params && digest_params_len) + format_bytes(fp, format, indent, "Parameters: ", digest_params, digest_params_len); + if (authed_attrs && authed_attrs_len) { + format_bytes(fp, format, indent, "AuthenticatedAttributes: ", authed_attrs, authed_attrs_len); + } + + format_print(fp, format, indent, "digestEncryptionAlgorithm: %s\n", x509_signature_algor_name(sign_algor)); + format_bytes(fp, format, indent, "encryptedDigest: ", sig, siglen); + if (unauthed_attrs && unauthed_attrs_len) { + format_bytes(fp, format, indent, "AuthenticatedAttributes: ", unauthed_attrs, unauthed_attrs_len); + } return 1; } @@ -1228,75 +1353,184 @@ int cms_signer_info_sign_to_der(const SM2_KEY *sm2_key, const SM3_CTX *sm3_ctx, return 1; } -int cms_signer_info_verify_from_der( +/* +1. 解析SignerInfo获得IssuerAndSerialNumber +2. 查找SignedData中的Certificates获得签名公钥 +3. 计算ContentInfo获得杂凑状态 +4. 加入AuthedAttributes得到杂凑值 +5. 验证签名 +*/ +int cms_signer_info_verify( const SM2_KEY *sm2_key, const SM3_CTX *sm3_ctx, - X509_NAME *issuer, const uint8_t **serial_number, size_t *serial_number_len, - int *digest_algor, uint32_t *digest_algor_nodes, size_t *digest_algor_nodes_count, - const uint8_t **authed_attrs, size_t *authed_attrs_len, - int *sign_algor, uint32_t *sign_algor_nodes, size_t *sign_algor_nodes_count, - const uint8_t **unauthed_attrs, size_t *unauthed_attrs_len, - const uint8_t **in, size_t *inlen) + const uint8_t *authed_attrs, size_t authed_attrs_len, + const uint8_t *sig, size_t siglen) { int ret; SM3_CTX ctx; uint8_t dgst[32]; - const uint8_t *sig; - size_t sig_len; - - if (cms_signer_info_from_der(issuer, serial_number, serial_number_len, - digest_algor, - authed_attrs, authed_attrs_len, - sign_algor, - &sig, &sig_len, - unauthed_attrs, unauthed_attrs_len, - in, inlen) != 1) { - error_print(); - return -1; - } - if (*digest_algor != OID_sm3) { - error_print(); - return -1; - } - if (*sign_algor != OID_sm2sign_with_sm3) { - error_print(); - return -1; - } memcpy(&ctx, sm3_ctx, sizeof(SM3_CTX)); if (*authed_attrs) { uint8_t header[8]; uint8_t *p = header; size_t header_len = 0; - asn1_set_header_to_der(*authed_attrs_len, &p, &header_len); + asn1_set_header_to_der(authed_attrs_len, &p, &header_len); sm3_update(&ctx, header, header_len); - sm3_update(&ctx, *authed_attrs, *authed_attrs_len); + sm3_update(&ctx, authed_attrs, authed_attrs_len); } sm3_finish(&ctx, dgst); - if ((ret = sm2_verify(sm2_key, dgst, sig, sig_len)) != 1) { + if ((ret = sm2_verify(sm2_key, dgst, sig, siglen)) != 1) { error_print(); return -1; } + return ret; } -/* -SignedData ::= SEQUENCE { - version INTEGER (1), - digestAlgorithms SET OF AlgorithmIdentifier, - contentInfo ContentInfo, - certificates [0] IMPLICIT SET OF Certificate OPTIONAL, - crls [1] IMPLICIT SET OF CertificateRevocationList OPTIONAL, - signerInfos SET OF SignerInfo -} -*/ +static int x509_digest_algors_print(FILE *fp, const uint8_t *p, size_t len, int format, int indent) +{ + int dgst_algor; + uint32_t dgst_algor_nodes[32]; + size_t dgst_algor_nodes_count; + format_print(fp, format, indent, "DigestAlgorithms:\n"); + + while (len) { + if (x509_digest_algor_from_der(&dgst_algor, + dgst_algor_nodes, &dgst_algor_nodes_count, + &p, &len) != 1) { + error_print(); + return -1; + } + format_print(fp, format, indent + 4, "%s\n", x509_digest_algor_name(dgst_algor)); + } + return 1; +} + + +static int x509_certificates_print(FILE *fp, const uint8_t *p, size_t len, int format, int indent) +{ + X509_CERTIFICATE cert; + + format_print(fp, format, indent, "Certificates:\n"); + indent += 4; + + while (len) { + if (x509_certificate_from_der(&cert, &p, &len) != 1) { + error_print(); + return -1; + } + x509_certificate_print(fp, &cert, format, indent); + } + return 1; +} + +static int x509_crls_print(FILE *fp, const uint8_t *p, size_t len, int format, int indent) +{ + /* + X509_CRL crl; + while (len) { + if (x509_crl_from_der(&crl, &p, &len) != 1) { + error_print(); + return -1; + } + x509_crl_print(fp, &crl, format, indent); + } + */ + return 1; +} + +static int cms_recipient_infos_print(FILE *fp, const uint8_t *p, size_t len, int format, int indent) +{ + format_print(fp, format, indent, "RecipientInfos:\n"); + while (len) { + int version; + X509_NAME issuer; + const uint8_t *serial_number; + size_t serial_number_len; + int pke_algor; + const uint8_t *pke_params; + size_t pke_params_len; + const uint8_t *enced_key; + size_t enced_key_len; + + if (cms_recipient_info_from_der( + &version, + &issuer, &serial_number, &serial_number_len, + &pke_algor, &pke_params, &pke_params_len, + &enced_key, &enced_key_len, + &p, &len) != 1) { + error_print(); + return -1; + } + + cms_recipient_info_print(fp, + version, + &issuer, serial_number, serial_number_len, + pke_algor, pke_params, pke_params_len, + enced_key, enced_key_len, + format, indent + 4); + } + + return 1; +} + + +static int cms_signer_infos_print(FILE *fp, const uint8_t *p, size_t len, int format, int indent) +{ + format_print(fp, format, indent, "SignerInfos:\n"); + indent += 4; + + while (len) { + int version; + X509_NAME issuer; + const uint8_t *serial_number; + size_t serial_number_len; + int digest_algor; + const uint8_t *digest_params; + size_t digest_params_len; + const uint8_t *authed_attrs; size_t authed_attrs_len; + int sign_algor; + const uint8_t *sign_params; + size_t sign_params_len; + const uint8_t *sig; + size_t siglen; + const uint8_t *unauthed_attrs; size_t unauthed_attrs_len; + + + cms_signer_info_from_der( + &issuer, + &serial_number, &serial_number_len, + &digest_algor, + &authed_attrs, &authed_attrs_len, + &sign_algor, + &sig, &siglen, + &unauthed_attrs, &unauthed_attrs_len, + &p, &len); + + cms_signer_info_print(fp, + version, + &issuer, + serial_number, serial_number_len, + digest_algor, digest_params, digest_params_len, + authed_attrs, authed_attrs_len, + sign_algor, sign_params, sign_params_len, + sig, siglen, + unauthed_attrs, unauthed_attrs_len, + format, indent); + } + + return 1; +} + +// 这个函数有用吗? int cms_signed_data_to_der( const int *digest_algors, const size_t digest_algors_count, const int content_type, const uint8_t *content, const size_t content_len, const X509_CERTIFICATE *certs, size_t certs_count, const uint8_t **crls, const size_t *crls_lens, const size_t crls_count, - const uint8_t **signer_infos, size_t *signer_infos_lens, size_t signer_infos_count, + const uint8_t **signer_infos, size_t *signer_infos_lens, size_t signer_infos_count,// 这个类型有点问题,意味着签名方必须把所有SignerInfo处理好才行 uint8_t **out, size_t *outlen) { size_t len = 0; @@ -1306,11 +1540,12 @@ int cms_signed_data_to_der( size_t signer_infos_len = 0; int i; - /* - for (i = 0; i < digest_algors_count; i++) + for (i = 0; i < digest_algors_count; i++) { x509_digest_algor_to_der(digest_algors[i], NULL, &digest_algors_len); - for (i = 0; i < certs_count; i++) + } + for (i = 0; i < certs_count; i++) { x509_certificate_to_der(&certs[i], NULL, &certs_len); + } for (i = 0; i < crls_count; i++) crls_len += crls_lens[i]; for (i = 0; i < signer_infos_count; i++) @@ -1326,7 +1561,7 @@ int cms_signed_data_to_der( return -1; } - if (asn1_sequence_to_der(len, out, outlen) != 1 + if (asn1_sequence_header_to_der(len, out, outlen) != 1 || asn1_int_to_der(CMS_version, out, outlen) != 1 || asn1_set_header_to_der(digest_algors_len, out, outlen) != 1) { error_print(); @@ -1356,13 +1591,12 @@ int cms_signed_data_to_der( } - if (asn1_set_to_der(signer_infos_len, out, outlen) != 1) { + if (asn1_set_header_to_der(signer_infos_len, out, outlen) != 1) { } for (i = 0; i < signer_infos_count; i++) { asn1_data_to_der(signer_infos[i], signer_infos_lens[i], out, outlen); } - */ return -1; } @@ -1383,93 +1617,144 @@ int cms_signed_data_from_der( if (ret < 0) error_print(); return ret; } + if (asn1_int_from_der(&version, &data, &datalen) != 1 || asn1_set_from_der(digest_algors, digest_algors_len, &data, &datalen) != 1 - || cms_content_info_from_der(content_type, content, content_len, &data, &datalen) != 1 - || asn1_implicit_set_from_der(0, certs, certs_len, &data, &datalen) < 0 - || asn1_implicit_set_from_der(1, crls, crls_len, &data, &datalen) < 0 - || asn1_set_from_der(signer_infos, signer_infos_len, &data, &datalen) != 1 - || datalen) { + || cms_content_info_from_der(content_type, content, content_len, &data, &datalen) != 1) { error_print(); return -1; } - if (version != CMS_version) { + + if ((ret = asn1_implicit_set_from_der(0, certs, certs_len, &data, &datalen)) < 0) { error_print(); return -1; } + if (ret == 0) { + // printf("no certs\n"); + } + + if ((ret = asn1_implicit_set_from_der(1, crls, crls_len, &data, &datalen)) < 0) { + error_print(); + return -1; + } + + + if (asn1_set_from_der(signer_infos, signer_infos_len, &data, &datalen) != 1) { + error_print(); + return -1; + } + + if (asn1_length_is_zero(datalen) != 1) { + error_print(); + //return -1; + } + if (version != CMS_version) { + error_print(); + //return -1; + } return 1; } -int cms_signed_data_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent) +static int content_info_print(FILE *fp, + int content_type, const uint8_t *content, size_t content_len, + int format, int indent) { - const uint8_t *data; - size_t datalen; - int version; - int algor; - uint32_t nodes[32]; - size_t nodes_count; - const uint8_t *certs; - size_t certslen; - const uint8_t *crls; - size_t crlslen; - const uint8_t *signer_infos; - size_t signer_infos_len; - - if (asn1_sequence_from_der(&data, &datalen, &a, &alen) != 1) { - error_print(); - return -1; + format_print(fp, format, indent, "ContentInfo:\n"); + indent += 4; + format_print(fp, format, indent, "Type : %s\n", cms_content_type_name(content_type)); + switch (content_type) { + case CMS_data: return cms_data_print(fp, content, content_len, format, indent); + case CMS_signed_data: return cms_signed_data_print(fp, content, content_len, format, indent); + case CMS_enveloped_data: break; + case CMS_signed_and_enveloped_data: break; + case CMS_encrypted_data: return cms_encrypted_data_print(fp, content, content_len, format, indent); + case CMS_key_agreement_info: return cms_key_agreement_info_print(fp, content, content_len, format, indent); } - - if (asn1_int_from_der(&version, &data, &datalen) != 1) goto bad; - format_print(fp, format, indent, "Version : %d\n", version); - - if (x509_digest_algor_from_der(&algor, nodes, &nodes_count, &data, &datalen) != 1) goto bad; - format_print(fp, format, indent, "DigestAlgorithm : %s\n", x509_digest_algor_name(algor)); - - if (asn1_implicit_sequence_from_der(0, &certs, &certslen, &data, &datalen) < 0) goto bad; - - if (asn1_implicit_sequence_from_der(1, &crls, &crlslen, &data, &datalen) < 0) goto bad; - - if (asn1_sequence_from_der(&signer_infos, &signer_infos_len, &data, &datalen) != 1) goto bad; - - -bad: error_print(); - return -1; } -int cms_signed_data_sign_to_der(const SM2_KEY *sign_keys, - const X509_CERTIFICATE *sign_certs, size_t sign_count, +// 这几个类型的打印有相当多的重复部分 +int cms_signed_data_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent) +{ + int version = 1; + const uint8_t *dgst_algors; + int content_type; + const uint8_t *content; + const uint8_t *certs; + const uint8_t *crls; + const uint8_t *signer_infos; + size_t dgst_algors_len, content_len, certs_len, crls_len, signer_infos_len; + + if (cms_signed_data_from_der( + &dgst_algors, &dgst_algors_len, + &content_type, &content, &content_len, + &certs, &certs_len, + &crls, &crls_len, + &signer_infos, &signer_infos_len, + &a, &alen) != 1) { + error_print(); + // return -1; + } + + format_print(fp, format, indent, "SignedData:\n"); + indent += 4; + format_print(fp, format, indent, "Version : %d\n", version); + x509_digest_algors_print(fp, dgst_algors, dgst_algors_len, format, indent); + content_info_print(fp, content_type, content, content_len, format, indent); + + x509_certificates_print(fp, certs, certs_len, format, indent); + + + x509_crls_print(fp, crls, crls_len, format, indent); + cms_signer_infos_print(fp, signer_infos, signer_infos_len, format, indent); + return 1; +} + +/* +SignedData ::= SEQUENCE { + version INTEGER (1), + digestAlgorithms SET OF AlgorithmIdentifier, + contentInfo ContentInfo, + certificates [0] IMPLICIT SET OF Certificate OPTIONAL, + crls [1] IMPLICIT SET OF CertificateRevocationList OPTIONAL, + signerInfos SET OF SignerInfo +} + +应该把CRL模块完成后再补全? +还是暂时不支持CRL? +*/ + +int cms_signed_data_sign_to_der( + const SM2_KEY *sign_keys, const X509_CERTIFICATE *sign_certs, size_t sign_count, int content_type, const uint8_t *content, size_t content_len, - const uint8_t **crls, size_t *crls_lens, size_t crls_count, + const uint8_t *crls, size_t crls_len, uint8_t **out, size_t *outlen) { uint8_t *p; size_t len = 0; - uint8_t digest_algors[16]; + uint8_t digest_algors[16]; // 这里我们只有一个哈希函数 size_t digest_algors_len = 0; - size_t sign_certs_len = 0; size_t certs_len = 0; - size_t crls_len = 0; size_t signer_infos_len = 0; uint8_t sigs[sign_count][SM2_MAX_SIGNATURE_SIZE]; size_t siglens[sign_count]; int i; + // digestAlgorithms p = digest_algors; x509_digest_algor_to_der(OID_sm3, &p, &digest_algors_len); + + // certificates for (i = 0; i < sign_count; i++) { - if (x509_certificate_to_der(&sign_certs[i], NULL, &sign_certs_len) != 1) { + if (x509_certificate_to_der(&sign_certs[i], NULL, &certs_len) != 1) { error_print(); return -1; } } - for (i = 0; i < crls_count; i++) { - crls_len += crls_lens[i]; - } + // signerInfos for (i = 0; i < sign_count; i++) { const X509_CERTIFICATE *cert = &sign_certs[i]; const X509_NAME *issuer = &cert->tbs_certificate.issuer; @@ -1478,7 +1763,7 @@ int cms_signed_data_sign_to_der(const SM2_KEY *sign_keys, SM2_SIGN_CTX sign_ctx; sm2_sign_init(&sign_ctx, &sign_keys[i], SM2_DEFAULT_ID); - sm2_sign_update(&sign_ctx, content, content_len); + sm2_sign_update(&sign_ctx, content, content_len); // 这里我们签名的都是content sm2_sign_finish(&sign_ctx, sigs[i], &siglens[i]); if (cms_signer_info_to_der(issuer, serial_number, serial_number_len, @@ -1489,6 +1774,7 @@ int cms_signed_data_sign_to_der(const SM2_KEY *sign_keys, } } + len = 0; if (asn1_int_to_der(CMS_version, NULL, &len) != 1 || asn1_set_to_der(digest_algors, digest_algors_len, NULL, &len) != 1 @@ -1500,7 +1786,6 @@ int cms_signed_data_sign_to_der(const SM2_KEY *sign_keys, return -1; } - if (asn1_sequence_header_to_der(len, out, outlen) != 1 || asn1_int_to_der(CMS_version, out, outlen) != 1 || asn1_set_to_der(digest_algors, digest_algors_len, out, outlen) != 1 @@ -1509,6 +1794,7 @@ int cms_signed_data_sign_to_der(const SM2_KEY *sign_keys, error_print(); return -1; } + for (i = 0; i < sign_count; i++) { if (x509_certificate_to_der(&sign_certs[i], out, outlen) != 1) { error_print(); @@ -1516,13 +1802,10 @@ int cms_signed_data_sign_to_der(const SM2_KEY *sign_keys, } } if (crls) { - if (asn1_implicit_set_header_to_der(1, crls_len, out, outlen) != 1) { + if (asn1_implicit_set_to_der(1, crls, crls_len, out, outlen) != 1) { error_print(); return -1; } - for (i = 0; i < crls_count; i++) { - asn1_data_to_der(crls[i], crls_lens[i], out, outlen); - } } asn1_set_header_to_der(signer_infos_len, out, outlen); for (i = 0; i < sign_count; i++) { @@ -1541,226 +1824,412 @@ int cms_signed_data_sign_to_der(const SM2_KEY *sign_keys, return 1; } -int cms_signed_data_verify_from_der(const uint8_t *signed_data, size_t signed_data_len) +// 这里的主要矛盾是验证过程没有必要返回那么多数据!只能造成工作量过大, +// 如果调用方想要获得相应的数据,可以自己来解析。 + + +int cms_signed_data_verify( + int content_type, const uint8_t *content, size_t content_len, // 被签名的到底是什么数据? + const uint8_t *certs, size_t certs_len, + const uint8_t *signer_infos, size_t signer_infos_len) { - int version; - int content_type; - const uint8_t *digest_algors; - const uint8_t *content; - const uint8_t *certs; - const uint8_t *crls; - const uint8_t *signer_infos; - size_t digest_algors_len; - size_t content_len; - size_t certs_len; - size_t crls_len; - size_t signer_infos_len; - /* - if (asn1_sequence_from_der(&data, &datalen, &signed_data, &signed_data_len) != 1 - || signed_data_len > 0) { - error_print(); - return -1; - } - if (asn1_int_from_der(&version, &data, &datalen) != 1 - || asn1_set_from_der(&digest_algors, &digest_algors_len, &data, &datalen) != 1 - || cms_content_info_from_der(&content_type, &content, &content_len, &data, &datalen) != 1 - || asn1_implicit_set_from_der(0, &certs, &certs_len, &data, &datalen) < 0 - || asn1_implicit_set_from_der(1, &crls, &crls_len, &data, &datalen) < 0 - || asn1_set_from_der(&signer_infos, &signer_infos_len, &data, &datalen) != 1) { - error_print(); - return -1; - } - - len = signer_infos_len; - - while (len > 0) { - cms_signer_info_from_der(); + assert(content); + assert(certs); + assert(signer_infos); - cms_signer_info_match(); + while (signer_infos_len) { - cms_signer_info_verify(); + X509_NAME issuer; + const uint8_t *serial_number; + size_t serial_number_len; + const uint8_t *authed_attrs; + size_t authed_attrs_len; + const uint8_t *unauthed_attrs; + size_t unauthed_attrs_len; + const uint8_t *sig; + size_t siglen; + int dgst_algor, sign_algor; + + cms_signer_info_from_der(&issuer, + &serial_number, &serial_number_len, + &dgst_algor, + &authed_attrs, &authed_attrs_len, + &sign_algor, + &sig, &siglen, + &unauthed_attrs, &unauthed_attrs_len, + &signer_infos, &signer_infos_len); + + + // 找到对应的SM2_KEY ,并且验证签名 + X509_CERTIFICATE cert; + + // 主要的挑战就是找到对应的张数 + find_cert(&cert, certs, certs_len, &issuer, serial_number, serial_number_len); + + const SM2_KEY *sign_key = &cert.tbs_certificate.subject_public_key_info.sm2_key; + + SM2_SIGN_CTX ctx; + + sm2_verify_init(&ctx, sign_key, SM2_DEFAULT_ID); + sm2_verify_update(&ctx, content, content_len); + + + if (authed_attrs) { + uint8_t header[8]; + uint8_t *p = header; + size_t header_len = 0; + + asn1_set_header_to_der(*authed_attrs, &p, &header_len); + sm2_verify_update(&ctx, header, header_len); + sm2_verify_update(&ctx, authed_attrs, authed_attrs_len); + } + + int ret; + ret = sm2_verify_finish(&ctx, sig, siglen); + + if (ret != 1) { + error_print_msg("sm2_verify_finish return %d\n", ret); + return -1; + } } - */ - return -1; + return 1; } +// 为什么不用这个函数 +int cms_signed_data_verify_from_der( + const uint8_t **digest_algors, size_t *digest_algors_len, + int *content_type, const uint8_t **content, size_t *content_len, + const uint8_t **certs, size_t *certs_len, + const uint8_t **crls, size_t *crls_len, + const uint8_t **signer_infos, size_t *signer_infos_len, + const uint8_t **in, size_t *inlen) +{ + int ret; + + if ((ret = cms_signed_data_from_der( + digest_algors, digest_algors_len, + content_type, content, content_len, + certs, certs_len, + crls, crls_len, + signer_infos, signer_infos_len, + in, inlen)) != 1) { + + if (ret < 0) error_print(); + return ret; + } + + if (cms_signed_data_verify( + *content_type, *content, *content_len, + *certs, *certs_len, + *signer_infos, *signer_infos_len) != 1) { + error_print(); + return -1; + } + + return 1; +} /* - - SignedAndEnvelopedData ::= SEQUENCE { version INTEGER (1), recipientInfos SET OF RecipientInfo, digestAlgorithms SET OF AlgorithmIdentifier, - encryptedContentInfo EncryptedContentInfo, + encryptedContentInfo EncryptedContentInfo ::= SEQUENCE { + contentType OBJECT IDENTIFIER, + contentEncryptionAlgorithm AlgorithmIdentifier, // 包含IV + encryptedContent [0] IMPLICIT OCTET STRING OPTIONAL, + sharedInfo1 [1] IMPLICIT OCTET STRING OPTIONAL, + sharedInfo2 [2] IMPLICIT OCTET STRING OPTIONAL, certificates [0] IMPLICIT SET OF Certificate OPTIONAL, crls [1] IMPLICIT SET OF CertificateRevocationList OPTIONAL, signerInfos SET OF SignerInfo } - */ +1. 生成随机的content-encryption key (CEK) +2. 用每个接收者的公钥加密CEK +3. 并形成RecipientInfo +4. 根据签名者的算法生成content的哈希值,目前只支持SM3算法,注意涉及Z值 +5. 用签名者的私钥对content的哈希值及authed_attrs进行签名,生成签名值,并且用CEK对签名值加密(可能需要填充) +6. 构造SignerInfos +7. 用CEK对ContentInfo.content中EXPLICIT [0]内部的ContentInfo的DER进行加密 +8. 组成一个SignedAndEnvelopedData -int cms_signed_and_enveloped_data_to_der(void) +注意: + +- 这是一个先签名再加密的过程 +- 每个签名值都被对称加密密钥独立加密了 + +*/ + +int cms_signed_and_enveloped_data_to_der( + int version, + const uint8_t *rcpt_infos, size_t rcpt_infos_len, + const int *digest_algors, size_t digest_algors_count, + int content_type, + int enc_algor, const uint8_t *enc_iv, size_t enc_iv_len, + const uint8_t *enced_content, size_t enced_content_len, + const uint8_t *shared_info1, size_t shared_info1_len, + const uint8_t *shared_info2, size_t shared_info2_len, + const X509_CERTIFICATE *certs, size_t certs_count, + const uint8_t *crls, size_t crls_count, + const uint8_t signer_infos, size_t signer_infos_len) { + + return -1; } -int cms_signed_and_enveloped_data_from_der(void) +int cms_signed_and_enveloped_data_from_der( + int *version, + const uint8_t **rcpt_infos, size_t *rcpt_infos_len, + const uint8_t **dgst_algors, size_t *dgst_algors_len, + int *content_type, + int *enc_algor, const uint8_t **enc_iv, size_t *enc_iv_len, + const uint8_t **enced_content, size_t *enced_content_len, + const uint8_t **shared_info1, size_t *shared_info1_len, + const uint8_t **shared_info2, size_t *shared_info2_len, + const uint8_t **certs, size_t *certs_len, + const uint8_t **crls, size_t *crls_len, + const uint8_t **signer_infos, size_t *signer_infos_len, + const uint8_t **in, size_t *inlen) { - return -1; + int ret; + const uint8_t *data; + size_t datalen; + + + if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { + if (ret < 0) error_print(); + return ret; + } + + if (asn1_int_from_der(version, &data, &datalen) != 1 + || asn1_set_from_der(rcpt_infos, rcpt_infos_len, &data, &datalen) != 1 + || asn1_set_from_der(dgst_algors, dgst_algors_len, &data, &datalen) != 1 + || cms_enced_content_info_from_der(content_type, + enc_algor, enc_iv, enc_iv_len, + enced_content, enced_content_len, + shared_info1, shared_info1_len, + shared_info2, shared_info2_len, + &data, &datalen) != 1 + || asn1_implicit_set_from_der(0, certs, certs_len, &data, &datalen) < 0 + || asn1_implicit_set_from_der(1, crls, crls_len, &data, &datalen) < 0 + || asn1_set_from_der(signer_infos, signer_infos_len, &data, &datalen) != 1 + || datalen > 0) { + error_print(); + return -1; + } + + return 1; } -int cms_signed_and_enveloped_data_print(void) +int cms_signed_and_enveloped_data_print(FILE *fp, const uint8_t *a, size_t alen, + int format, int indent) { - return -1; + int version; + const uint8_t *rcpt_infos; + const uint8_t *dgst_algors; + const uint8_t *certs; + const uint8_t *crls; + const uint8_t *signer_infos; + size_t rcpt_infos_len, dgst_algors_len, certs_len, crls_len, signer_infos_len; + int content_type; + int enc_algor; + const uint8_t *enc_iv; + const uint8_t *enced_content; + const uint8_t *shared_info1; + const uint8_t *shared_info2; + size_t enc_iv_len, enced_content_len, shared_info1_len, shared_info2_len; + + cms_signed_and_enveloped_data_from_der( + &version, + &rcpt_infos, &rcpt_infos_len, + &dgst_algors, &dgst_algors_len, + &content_type, + &enc_algor, &enc_iv, &enc_iv_len, + &enced_content, &enced_content_len, + &shared_info1, &shared_info1_len, + &shared_info2, &shared_info2_len, + &certs, &certs_len, + &crls, &crls_len, + &signer_infos, &signer_infos_len, + &a, &alen); + + + format_print(fp, format, indent, "SignedAndEnvelopedData:\n"); + indent += 4; + + format_print(fp, format, indent, "Version: %d\n", version); + cms_recipient_infos_print(fp, rcpt_infos, rcpt_infos_len, format, indent); + x509_digest_algors_print(fp, dgst_algors, dgst_algors_len, format, indent); + cms_enced_content_info_print(fp, + content_type, + enc_algor, enc_iv, enc_iv_len, + enced_content, enced_content_len, + shared_info1, shared_info1_len, + shared_info2, shared_info2_len, + format, indent); + x509_certificates_print(fp, certs, certs_len, format, indent); + x509_crls_print(fp, crls, crls_len, format, indent); + cms_signer_infos_print(fp, signer_infos, signer_infos_len, format, indent); + + return 1; } +/* +SignedAndEnvelopedData ::= SEQUENCE { + version INTEGER (1), + recipientInfos SET OF RecipientInfo, + digestAlgorithms SET OF AlgorithmIdentifier, + encryptedContentInfo EncryptedContentInfo ::= SEQUENCE { + contentType OBJECT IDENTIFIER, + contentEncryptionAlgorithm AlgorithmIdentifier, // 包含IV + encryptedContent [0] IMPLICIT OCTET STRING OPTIONAL, + sharedInfo1 [1] IMPLICIT OCTET STRING OPTIONAL, + sharedInfo2 [2] IMPLICIT OCTET STRING OPTIONAL, + certificates [0] IMPLICIT SET OF Certificate OPTIONAL, + crls [1] IMPLICIT SET OF CertificateRevocationList OPTIONAL, + signerInfos SET OF SignerInfo +} + + +1. 生成随机的content-encryption key (CEK) +2. 用每个接收者的公钥加密CEK +3. 并形成RecipientInfo +4. 根据签名者的算法生成content的哈希值,目前只支持SM3算法,注意涉及Z值 +5. 用签名者的私钥对content的哈希值及authed_attrs进行签名,生成签名值,并且用CEK对签名值加密(可能需要填充) +6. 构造SignerInfos +7. 用CEK对ContentInfo.content中EXPLICIT [0]内部的ContentInfo的DER进行加密 + +*/ + +// 这个接口是有问题的,显然签名方的证书和密钥没有给出了! int cms_signed_and_enveloped_data_sign_encrypt_to_der( - const int *digest_algors, const size_t digset_algors_count, - const X509_CERTIFICATE *sign_certs, size_t sign_count, - const uint8_t **crls, const size_t *crls_lens, const size_t crls_count, - const uint8_t **signer_infos, size_t *signer_infos_lens, size_t signer_infos_count, + const SM2_KEY *sign_keys, const X509_CERTIFICATE *sign_certs, size_t sign_count, + const uint8_t *sign_crls, const size_t sign_crls_len, const X509_CERTIFICATE *rcpt_certs, size_t rcpt_count, int content_type, const uint8_t *content, size_t content_len, const uint8_t *shared_info1, size_t shared_info1_len, const uint8_t *shared_info2, size_t shared_info2_len, + uint8_t **out, size_t *outlen) { -/* - size_t len = 0; - SM4_KEY sm4_key; - uint8_t enc_key[16]; - uint8_t enc_iv[16]; - uint8_t enced_key[rcpt_count][256 + 16]; - uint8_t enced_content_info[content_len + 512]; - size_t enced_content_info_len; - rand_bytes(enc_key, 16); - rand_bytes(enc_iv, 16); - - size_t i; - for (i = 0; i < rcpt_count; i++) { - const SM2_KEY *sm2_key = x509_certificate_get_public_key(rcpt_certs[i]); - sm2_encrypt(sm2_key, enc_key, 16, enced_key[i], enced_key_len[i]); - } - - for (i = 0; i < rcpt_count; i++) { - x509_certificate_get_recipient_info(rcpt_cert, - &issuer, - &serial_number, &serial_number_len, - &sm2_key); - - cms_recipient_info_encrypt_to_der(issuer, - serial_number, serial_number_len, - enced_key, enced_key_len, - NULL, &rcpt_infos_len); - } - - if (asn1_int_to_der(CMS_version, NULL, &len) != 1 - || asn1_set_to_der(NULL, rcpt_infos_len, NULL, &len) != 1 - || cms_enced_content_info_encrypt_to_der(&sm4_key, enc_iv, - content_type, content, content_len, - shared_info1, shared_info1_len, - shared_info2, shared_info2_len, - NULL, &len) != 1) { - error_print(); - return -1; - } - - if (asn1_sequence_header_to_der(len, out, outlen) != 1 - || asn1_int_to_der(CMS_version, out, outlen) != 1 - || asn1_set_header_to_der(rcpt_infos_len, out, outlen) != 1) { - error_print(); - return -1; - } - for (i = 0; i < rcpt_count; i++) { - if (cms_recipient_info_encrypt_to_der(&sm2_key, issuer, - serial_number, serial_number_len, - enc_key, sizeof(enc_key), out, outlen) != 1) { - error_print(); - return -1; - } - } - if (cms_enced_content_info_encrypt_to_der(&sm4_key, enc_iv, - content_type, content, content_len, - shared_info1, shared_info1_len, - shared_info2, shared_info2_len, - out, &outlen) != 1) { - error_print(); - return -1; - } -*/ return 1; } -int cms_signed_and_enveloped_data_decrypt_verify_from_der() +/* +我们需要保证提供的私钥和证书可以和某个rcpt_infos匹配 +还有一个问题是,在验签之后,我们需要返回所有的证书吗?不需要的,只要可以解析就可以了 +函数保证signer_infos +*/ +int cms_signed_and_enveloped_data_decrypt_verify_from_der( + const SM2_KEY *dec_key, const X509_CERTIFICATE *dec_cert, + const uint8_t **rcpt_infos, size_t *rcpt_infos_len, + const uint8_t **dgst_algors, size_t *dgst_algors_len, + int *content_type, + int *enc_algor, const uint8_t **enc_iv, size_t *enc_iv_len, + const uint8_t **enced_content, size_t *enced_content_len, + const uint8_t **shared_info1, size_t *shared_info1_len, + const uint8_t **shared_info2, size_t *shared_info2_len, + const uint8_t **certs, size_t *certs_len, + const uint8_t **crls, size_t *crls_len, + const uint8_t **signer_infos, size_t *signer_infos_len) { + + /* + signer_info 中的签名是针对未加密的content的 + 因此我们需要首先解析数据结构 + 找到一个和证书、私钥匹配的recipient_info + 解密得到数据加密密钥,并解密enced_content + 然后验证所有的signer_infos + + 这意味着这个函数应该可以和signed_data, enveloped_data共享某些函数 + */ + + + + + + + + + + + return -1; } - - int cms_content_info_print(FILE *fp, const uint8_t *a, size_t alen, int format, int indent) { - int ret; - int oid; - const uint8_t *data; - size_t datalen; - uint32_t nodes[32]; - size_t nodes_count; + int content_type; const uint8_t *content; size_t content_len; - format_print(fp, format, indent, "ContentInfo:\n"); - indent += 4; - if ((ret = asn1_sequence_from_der(&data, &datalen, &a, &alen)) != 1) { + if (cms_content_info_from_der(&content_type, &content, &content_len, &a, &alen) != 1) { error_print(); return -1; } - - if (cms_content_type_from_der(&oid, &data, &datalen) != 1) goto bad; - format_print(fp, format, indent, "Type : %s\n", cms_content_type_name(oid)); - if (asn1_explicit_from_der(0, &content, &content_len, &data, &datalen) != 1) goto bad; - - switch (oid) { - case CMS_data: return cms_data_print(fp, content, content_len, format, indent); - case CMS_signed_data: return cms_signed_data_print(fp, content, content_len, format, indent); - case CMS_enveloped_data: break; - case CMS_signed_and_enveloped_data: break; - case CMS_encrypted_data: return cms_encrypted_data_print(fp, content, content_len, format, indent); - case CMS_key_agreement_info: - break; + if (content_info_print(fp, content_type, content, content_len, format, indent) != 1) { + error_print(); + return -1; + } + if (alen) { + error_print_msg("left length = %zu\n", alen); + format_bytes(stderr, 0, 0, "left ", a, alen); + return -1; } - return 1; -bad: - error_print(); - return -1; + return 1; } + + + // 下面的函数生成的都是ContentInfo +// 因此不简单是之前_to_der的封装,而是要组装成 // EncryptedData int cms_encrypt(const uint8_t key[16], const uint8_t *in, size_t inlen, uint8_t *out, size_t *outlen) { + size_t len = 0; + size_t content_len = 0; SM4_KEY sm4_key; uint8_t iv[16]; - int content_type = CMS_data; sm4_set_encrypt_key(&sm4_key, key); rand_bytes(iv, sizeof(iv)); if (cms_encrypted_data_encrypt_to_der(&sm4_key, iv, - content_type, in, inlen, NULL, 0, NULL, 0, - &out, outlen) != 1) { + CMS_data, in, inlen, NULL, 0, NULL, 0, + NULL, &content_len) != 1) { + error_print(); + return -1; + } + + if (cms_content_type_to_der(CMS_encrypted_data, NULL, &len) != 1 + || asn1_explicit_to_der(0, NULL, content_len, NULL, &len) != 1) { + error_print(); + return -1; + } + + + *outlen = 0; + if (asn1_sequence_header_to_der(len, &out, outlen) != 1 + || cms_content_type_to_der(CMS_encrypted_data, &out, outlen) != 1 + || asn1_explicit_header_to_der(0, content_len, &out, outlen) != 1) { + } + + if (cms_encrypted_data_encrypt_to_der(&sm4_key, iv, CMS_data, in, inlen, + NULL, 0, NULL, 0, &out, outlen) != 1) { error_print(); return -1; } @@ -1768,121 +2237,271 @@ int cms_encrypt(const uint8_t key[16], const uint8_t *in, size_t inlen, return 1; } +/* +一般来说,EncryptedData.EncryptedContent.contentType应该是CMS_data +但是也不排除是其他的类型,因此我们需要将这个类型反馈给调用方 +如果是其他类型,那么调用方可以进一步处理 +*/ int cms_decrypt(const uint8_t key[16], const uint8_t *in, size_t inlen, - int *content_type, uint8_t *out, size_t *outlen, - const uint8_t **shared_info1, size_t *shared_info1_len, - const uint8_t **shared_info2, size_t *shared_info2_len) + int *content_type, uint8_t *out, size_t *outlen) { - SM4_KEY sm4_key; + int cms_type; + const uint8_t *enced_content; + size_t enced_content_len; - sm4_set_decrypt_key(&sm4_key, key); - if (cms_encrypted_data_decrypt_from_der(&sm4_key, - content_type, out, outlen, - shared_info1, shared_info1_len, - shared_info2, shared_info2_len, + SM4_KEY sm4_key; + const uint8_t *shared_info1; + const uint8_t *shared_info2; + size_t shared_info1_len, shared_info2_len; + + // decode ContentInfo + if (cms_content_info_from_der(&cms_type, &enced_content, &enced_content_len, &in, &inlen) != 1) { error_print(); return -1; } + if (cms_type != CMS_encrypted_data) { + error_print(); + return -1; + } if (inlen) { + error_print(); + return -1; + } + + // decode EncryptedContentInfo + + sm4_set_decrypt_key(&sm4_key, key); + if (cms_encrypted_data_decrypt_from_der(&sm4_key, + content_type, out, outlen, + &shared_info1, &shared_info1_len, + &shared_info2, &shared_info2_len, + &enced_content, &enced_content_len) != 1) { + error_print(); + return -1; + } + if (enced_content_len) { error_print(); return 0; } + + if (shared_info1) { + format_bytes(stderr, 0, 0, "SharedInfo1: ", shared_info1, shared_info1_len); + } + if (shared_info2) { + format_bytes(stderr, 0, 0, "SharedInfo1: ", shared_info2, shared_info2_len); + } + + return 1; } -// EnvelopedData +// EnvelopedData,其实这个接口可能不是特别好用 +/* + 首先必须考虑到底解密方的证书到底是怎么获得的?如果是多个证书,是从PEM文件中还是从什么方式获得的? + +一般来说,我们在用cms命令行加密的时候,命令的输入应该是多个独立的证书文件。 +那么对我们来说,我们还是直接将证书 + +我觉得还是提供多个独立的证书比较符合实际的需求 + +*/ int cms_seal(const X509_CERTIFICATE *rcpt_certs, size_t rcpt_count, - int content_type, const uint8_t *content, size_t content_len, - const uint8_t *shared_info1, size_t shared_info1_len, - const uint8_t *shared_info2, size_t shared_info2_len, + const uint8_t *in, size_t inlen, uint8_t *out, size_t *outlen) { - return -1; + *outlen = 0; + if (cms_enveloped_data_encrypt_to_der( + rcpt_certs, rcpt_count, + CMS_data, in, inlen, + NULL, 0, NULL, 0, + &out, outlen) != 1) { + error_print(); + return -1; + } + + return 1; } int cms_open(const SM2_KEY *sm2_key, const X509_CERTIFICATE *cert, - const uint8_t *enveloped_data, size_t enveloped_data_len, - int *content_type, uint8_t *content, size_t *content_len) + const uint8_t *in, size_t inlen, + int *content_type, uint8_t *out, size_t *outlen) { - return -1; + const uint8_t *shared_info1; + const uint8_t *shared_info2; + size_t shared_info1_len, shared_info2_len; + + if (cms_enveloped_data_decrypt_from_der( + sm2_key, cert, + content_type, out, outlen, + &shared_info1, &shared_info1_len, + &shared_info2, &shared_info2_len, + &in, &inlen) != 1) { + error_print(); + return -1; + } + + if (inlen) { + error_print(); + return -1; + } + + return 1; } - -// SignedData -int cms_sign(const SM2_KEY *sign_keys, - const X509_CERTIFICATE *sign_certs, size_t sign_count, - int content_type, const uint8_t *content, size_t content_len, - const uint8_t **crls, size_t *crls_lens, size_t crls_count, - uint8_t *content_info, size_t *content_info_len) +/* +SM2签名值由于INTEGER编码的问题可能导致编码长度不固定 +因此通常情况下无法预知SignerInfo, SignedData的准确编码长度 +这个问题可以通过对SM2签名模块进行修改来保证签名长度固定 +即使如此,还需要在这个模块中检查signed_data_to_der两次输出长度是相同的 +*/ +int cms_sign(const SM2_KEY *sign_keys, const X509_CERTIFICATE *sign_certs, size_t sign_count, + const uint8_t *in, size_t inlen, uint8_t *out, size_t *outlen) { size_t len = 0; size_t signed_data_len = 0; + uint8_t *crls = NULL; + size_t crls_len = 0; + + size_t len2 = 0; if (cms_signed_data_sign_to_der(sign_keys, sign_certs, sign_count, - content_type, content, content_len, crls, crls_lens, crls_count, + CMS_data, in, inlen, crls, crls_len, NULL, &signed_data_len) != 1) { error_print(); return -1; } if (cms_content_type_to_der(CMS_signed_data, NULL, &len) != 1 - || asn1_explicit_to_der(0, NULL, signed_data_len, NULL, &len) != 1 - || asn1_sequence_header_to_der(len, &content_info, content_info_len) != 1 - || cms_content_type_to_der(CMS_signed_data, &content_info, content_info_len) != 1 - || asn1_explicit_header_to_der(0, signed_data_len, &content_info, content_info_len) != 1 - || cms_signed_data_sign_to_der(sign_keys, sign_certs, sign_count, - content_type, content, content_len, crls, crls_lens, crls_count, - &content_info, content_info_len) != 1) { + || asn1_explicit_to_der(0, NULL, signed_data_len, NULL, &len) != 1) { error_print(); return -1; } + + *outlen = 0; + if (asn1_sequence_header_to_der(len, &out, outlen) != 1 + || cms_content_type_to_der(CMS_signed_data, &out, outlen) != 1 + || asn1_explicit_header_to_der(0, signed_data_len, &out, outlen) != 1 + || cms_signed_data_sign_to_der(sign_keys, sign_certs, sign_count, + CMS_data, in, inlen, crls, crls_len, + &out, &len2) != 1) { + error_print(); + return -1; + } + + if (len2 != signed_data_len) { + error_print(); + + error_print_msg("len = %zu\n", len2); + error_print_msg("signed_data_len = %zu\n", signed_data_len); + + return -1; + } + + *outlen += signed_data_len; return 1; } +// SignedData 中包含被被签名数据、签名值、签名方的证书,因此是完整的 +// 并且包含多个签名值 +// 签名验证成功或者失败,应该返回一些信息,比如到底有哪些签名方?或者验签失败是哪个失败了? +// 我们不太容易反馈复杂的错误信息 +// 如果是命令行,我们需要输出数据和签名者的信息 +// 签名者除了打印名字,还应该把签名者的证书输出出来 +// 这里面主要的问题是,是否需要提供部分数据呢?我看是不需要的,因此必须能够获得被签名的数据和签名者的证书 +// 因此还是调用from_der比较好吧 +// 我们应该把一些相关信息直接打印出来! + int cms_verify(int *content_type, const uint8_t **content, size_t *content_len, - const uint8_t *content_info, size_t content_info_len) + const uint8_t **certs, size_t *certs_len, + const uint8_t **crls, size_t *crls_len, + const uint8_t **signer_infos, size_t *signer_infos_len, + const uint8_t *in, size_t inlen) { - return -1; + int cms_type; + const uint8_t *data; + size_t datalen; + + const uint8_t *dgst_algors; + size_t dgst_algors_len; + + + if (cms_content_info_from_der(&cms_type, &data, &datalen, &in, &inlen) != 1) { + error_print(); + return -1; + } + if (cms_type != CMS_signed_data) { + error_print(); + return -1; + } + + if (cms_signed_data_verify_from_der( + &dgst_algors, &dgst_algors_len, + content_type, content, content_len, + certs, certs_len, + crls, crls_len, + signer_infos, signer_infos_len, + &data, &datalen) != 1 + || asn1_length_is_zero(datalen) != 1) { + error_print(); + return -1; + } + + + + return 1; } - - - - - - - - -// SignedAndEnvelopedData -int cms_sign_and_seal( - const SM2_KEY *sign_keys, const X509_CERTIFICATE *sign_certs, size_t sign_count, - const uint8_t *crls, const size_t *crls_lens, const size_t crls_count, +/* +由于这组接口提供相对简化的接口,因此不是必须的输入都被忽略了 +*/ +int cms_sign_and_seal(const SM2_KEY *sign_keys, + const X509_CERTIFICATE *sign_certs, size_t sign_count, const X509_CERTIFICATE *rcpt_certs, size_t rcpt_count, - int content_type, const uint8_t *content, size_t content_len, - const uint8_t *shared_info1, size_t shared_info1_len, - const uint8_t *shared_info2, size_t shared_info2_len, + const uint8_t *in, size_t inlen, uint8_t *out, size_t *outlen) { - return -1; + int content_type = CMS_data; + const uint8_t *shared_info1 = NULL; + const uint8_t *shared_info2 = NULL; + size_t shared_info1_len = 0, shared_info2_len = 0; + + const uint8_t *sign_crls = NULL; + size_t sign_crls_len = 0; + + *outlen = 0; + cms_signed_and_enveloped_data_sign_encrypt_to_der( + sign_keys, sign_certs, sign_count, + sign_crls, sign_crls_len, + rcpt_certs, rcpt_count, + content_type, in, inlen, + shared_info1, shared_info1_len, + shared_info2, shared_info2_len, + &out, outlen); + + return 1; } -int cms_open_and_verify() +/* +1997 int cms_signed_and_enveloped_data_decrypt_verify_from_der( +1998 const SM2_KEY *dec_key, const X509_CERTIFICATE *dec_cert, +1999 const uint8_t **rcpt_infos, size_t *rcpt_infos_len, +2000 const uint8_t **dgst_algors, size_t *dgst_algors_len, +2001 int *content_type, +2002 int *enc_algor, const uint8_t **enc_iv, size_t *enc_iv_len, +2003 const uint8_t **enced_content, size_t *enced_content_len, +2004 const uint8_t **shared_info1, size_t *shared_info1_len, +2005 const uint8_t **shared_info2, size_t *shared_info2_len, +2006 const uint8_t **certs, size_t *certs_len, +2007 const uint8_t **crls, size_t *crls_len, +2008 const uint8_t **signer_infos, size_t *signer_infos_len) +*/ +int cms_open_and_verify( + const SM2_KEY *sm2_key, const X509_CERTIFICATE *cert, + const uint8_t *in, size_t inlen, + int *content_type, uint8_t *out, size_t *outlen) { + return -1; } - - - - - - - - - - - - - - diff --git a/src/debug.c b/src/debug.c index e4b672c8..43137db1 100644 --- a/src/debug.c +++ b/src/debug.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include @@ -98,6 +66,12 @@ int format_print(FILE *fp, int format, int indent, const char *str, ...) int format_bytes(FILE *fp, int format, int indent, const char *str, const uint8_t *data, size_t datalen) { int i; + + if (datalen > 4096) { + error_print(); + return -1; + } + for (i = 0; i < indent; i++) { fprintf(fp, " "); } diff --git a/src/des.c b/src/des.c index 98df6f43..b7b3a5c8 100644 --- a/src/des.c +++ b/src/des.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/digest.c b/src/digest.c index 2f550360..4b29150d 100644 --- a/src/digest.c +++ b/src/digest.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/endian.h b/src/endian.h index 590dccfc..47fa3871 100644 --- a/src/endian.h +++ b/src/endian.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_ENDIAN_H diff --git a/src/gcm.c b/src/gcm.c index 0fba87d1..5f639971 100644 --- a/src/gcm.c +++ b/src/gcm.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/gf128.c b/src/gf128.c index 1b77f92f..baa55d43 100644 --- a/src/gf128.c +++ b/src/gf128.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* GF(2^128) defined by f(x) = x^128 + x^7 + x^2 + x + 1 diff --git a/src/hash_drbg.c b/src/hash_drbg.c index e559b1ae..706616fb 100644 --- a/src/hash_drbg.c +++ b/src/hash_drbg.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/hex.c b/src/hex.c index ea59bd06..b6abec81 100644 --- a/src/hex.c +++ b/src/hex.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/hkdf.c b/src/hkdf.c index 6a851e7f..db19c844 100644 --- a/src/hkdf.c +++ b/src/hkdf.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/hmac.c b/src/hmac.c index ff5c727a..2f9ead75 100644 --- a/src/hmac.c +++ b/src/hmac.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/md5.c b/src/md5.c old mode 100755 new mode 100644 index fcab99e4..626e1c47 --- a/src/md5.c +++ b/src/md5.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/mem.h b/src/mem.h index 0b210440..90680c6e 100644 --- a/src/mem.h +++ b/src/mem.h @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_MEM_H diff --git a/src/nginx.c b/src/nginx.c new file mode 100644 index 00000000..08a08ce0 --- /dev/null +++ b/src/nginx.c @@ -0,0 +1,35 @@ + + + + +int ssl_init(void) +{ + // 不需要这个函数 + return 1; +} + +typedef struct { +} SSL_CTX; + + +// nginx中用的是PEM + +int ssl_use_certificate() +{ +} + +int ssl_use_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *cert, ngx_str_t *key, ngx_array_t *passwords) +{ +} + + +ngx_ssl_ciphers SSL_CTX_set_cipher_list + +ngx_ssl_client_certificate SSL_CTX_set_verify + SSL_CTX_set_verify_depth + SSL_CTX_load_verify_locations + SSL_load_client_CA_file + +ngx_ssl_trusted_certificate SSL_CTX_set_verify + SSL_CTX_set_verify_depth + SSL_CTX_load_verify_locations diff --git a/src/oid.c b/src/oid.c index 4bf59bf4..c92ae481 100644 --- a/src/oid.c +++ b/src/oid.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ @@ -821,6 +789,11 @@ const char *asn1_object_identifier_description(int oid) return NULL; } + +// FIXME: 这个测试函数都应该挪到测试目录中去 + + + // 测试 oid_nodes 编解码是否正确 // FIXME: 还应该增加一些外部的测试用例 int test_asn1_oid_nodes(void) diff --git a/src/pbkdf2.c b/src/pbkdf2.c index f6f6efd3..c0c9eac3 100644 --- a/src/pbkdf2.c +++ b/src/pbkdf2.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/pem.c b/src/pem.c index 233dba75..3986c65e 100644 --- a/src/pem.c +++ b/src/pem.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/pkcs8.c b/src/pkcs8.c index c3c19380..30d1c42c 100644 --- a/src/pkcs8.c +++ b/src/pkcs8.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/rand.c b/src/rand.c index ec07306d..cf5403e9 100644 --- a/src/rand.c +++ b/src/rand.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/rc4.c b/src/rc4.c index 9ebee294..46c978c3 100644 --- a/src/rc4.c +++ b/src/rc4.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/sha1.c b/src/sha1.c old mode 100755 new mode 100644 index 1514eaf1..79bfea18 --- a/src/sha1.c +++ b/src/sha1.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/sha256.c b/src/sha256.c old mode 100755 new mode 100644 index 37fc9fd3..9340c38a --- a/src/sha256.c +++ b/src/sha256.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/sha512.c b/src/sha512.c old mode 100755 new mode 100644 index e278cfc3..e644e8f2 --- a/src/sha512.c +++ b/src/sha512.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/sm2_algo.c b/src/sm2_algo.c index 62e50288..8189f975 100644 --- a/src/sm2_algo.c +++ b/src/sm2_algo.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ @@ -1497,7 +1465,7 @@ int sm2_do_verify(const SM2_KEY *key, const uint8_t dgst[32], const SM2_SIGNATUR if (bn_cmp(e, r) == 0) { return 1; } else { - error_print(); + error_print(); // 此处不应该打印错误,因为验证失败是预期的返回结果之一 return 0; } } @@ -1632,6 +1600,7 @@ int sm2_do_decrypt(const SM2_KEY *key, const SM2_CIPHERTEXT *in, uint8_t *out, s for (i = 0; i < inlen; i++) { out[i] ^= in->ciphertext[i]; } + *outlen = inlen; // u = Hash(x2 || M || y2) sm3_init(&sm3_ctx); diff --git a/src/sm2_asn1.c b/src/sm2_asn1.c index 59bbbbea..96091cdb 100644 --- a/src/sm2_asn1.c +++ b/src/sm2_asn1.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include @@ -136,6 +104,14 @@ int sm2_signature_from_der(SM2_SIGNATURE *sig, const uint8_t **in, size_t *inlen return 1; } +/* +SM2Cipher ::= SEQUENCE { + XCoordinate INTEGER, // 变长 + YCoordinate INTEGER, // 变长 + HASH OCTET STRING SIZE(32), + CipherText OCTET STRING +} +*/ int sm2_ciphertext_to_der(const SM2_CIPHERTEXT *c, uint8_t **out, size_t *outlen) { size_t len = 0; diff --git a/src/sm2_lib.c b/src/sm2_lib.c index fd5b2c66..0f631341 100644 --- a/src/sm2_lib.c +++ b/src/sm2_lib.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ @@ -96,11 +64,12 @@ int sm2_verify(const SM2_KEY *key, const uint8_t dgst[32], const uint8_t *der, s return -2; } if ((ret = sm2_do_verify(key, dgst, &sig)) != 1) { - error_print(); + error_print(); // 此处应该判断ret是否为0,如果返回的是0,那么不应该输出错误日志,会产生不必要的终端输出 } return ret; } +//FIXME: 由于每次加密的时候密文编码长度不同,因此这个函数应该避免在out == NULL时输出一个长度! int sm2_encrypt(const SM2_KEY *key, const uint8_t *in, size_t inlen, uint8_t *out, size_t *outlen) { size_t clen = SM2_CIPHERTEXT_SIZE(inlen); @@ -164,7 +133,12 @@ int sm2_compute_z(uint8_t z[32], const SM2_POINT *pub, const char *id) 0x00, 0x00, 0x00, 0x00, 0x06, 0x90, }; - if (!id || strcmp(id, "1234567812345678")) { + if (!z || !pub || !id) { + error_print(); + return -1; + } + + if (strcmp(id, "1234567812345678") == 0) { uint32_t digest[8] = { 0xadadedb5U, 0x0446043fU, 0x08a87aceU, 0xe86d2243U, 0x8e232383U, 0xbfc81fe2U, 0xcf9117c8U, 0x4707011dU, @@ -199,7 +173,7 @@ int sm2_compute_z(uint8_t z[32], const SM2_POINT *pub, const char *id) sm3_finish(&ctx, z); } - return 0; + return 1; } int sm2_sign_init(SM2_SIGN_CTX *ctx, const SM2_KEY *key, const char *id) diff --git a/src/sm2_prn.c b/src/sm2_prn.c index e52cdf93..3868c573 100644 --- a/src/sm2_prn.c +++ b/src/sm2_prn.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ @@ -53,16 +21,14 @@ #include #include - +// FIXME: 缺乏打印公钥的函数,有时候SM2_KEY中只有公钥,没有私钥 int sm2_key_print(FILE *fp, const SM2_KEY *key, int format, int indent) { format_print(fp, format, indent, "SM2PrivateKey\n"); indent += 4; format_bytes(fp, format, indent, "private_key : ", key->private_key, 32); - format_print(fp, format, indent, "public_key\n"); + format_print(fp, format, indent, "public_key:\n"); sm2_point_print(fp, &key->public_key, format, indent + 4); - //format_bytes(fp, format, indent + 4, "x : ", (uint8_t *)&key->public_key, 32); - //format_bytes(fp, format, indent + 4, "y : ", (uint8_t *)&key->public_key + 32, 32); return 1; } diff --git a/src/sm3.c b/src/sm3.c old mode 100755 new mode 100644 index b279d777..7336b7f0 --- a/src/sm3.c +++ b/src/sm3.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/sm3_hmac.c b/src/sm3_hmac.c index 96bb0c67..0398139d 100644 --- a/src/sm3_hmac.c +++ b/src/sm3_hmac.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/sm4_common.c b/src/sm4_common.c index 1254736d..4113b58c 100644 --- a/src/sm4_common.c +++ b/src/sm4_common.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "sm4_lcl.h" diff --git a/src/sm4_enc.c b/src/sm4_enc.c index 0efb53ac..a5cc1810 100644 --- a/src/sm4_enc.c +++ b/src/sm4_enc.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/sm4_lcl.h b/src/sm4_lcl.h index 7f03a735..9293824c 100644 --- a/src/sm4_lcl.h +++ b/src/sm4_lcl.h @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2019 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #ifndef GMSSL_SM4_LCL_H diff --git a/src/sm4_modes.c b/src/sm4_modes.c index ce37d258..c4f7adea 100644 --- a/src/sm4_modes.c +++ b/src/sm4_modes.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/sm4_setkey.c b/src/sm4_setkey.c index a8757cdb..11af58da 100644 --- a/src/sm4_setkey.c +++ b/src/sm4_setkey.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2019 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/sm9_keygen.c b/src/sm9_keygen.c index 0dbe5a9f..90229f3d 100644 --- a/src/sm9_keygen.c +++ b/src/sm9_keygen.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/sm9_math.c b/src/sm9_math.c index 8cd0390b..ac7d9ccb 100644 --- a/src/sm9_math.c +++ b/src/sm9_math.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/sm9_sign.c b/src/sm9_sign.c index 34f10e96..41a93970 100644 --- a/src/sm9_sign.c +++ b/src/sm9_sign.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ int sm9_sign_setup(SM9_SIGN_MASTER_KEY *msk) diff --git a/src/tlcp.c b/src/tlcp.c index 960d88f0..2fdf3101 100644 --- a/src/tlcp.c +++ b/src/tlcp.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/tls.c b/src/tls.c index 94235c65..8dbeea9b 100644 --- a/src/tls.c +++ b/src/tls.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/tls12.c b/src/tls12.c index 155f372d..af7f4877 100644 --- a/src/tls12.c +++ b/src/tls12.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/tls13.c b/src/tls13.c index 9f7d464a..1f9d7f50 100644 --- a/src/tls13.c +++ b/src/tls13.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/src/tls_trace.c b/src/tls_trace.c index 3fefb66f..9df0d447 100644 --- a/src/tls_trace.c +++ b/src/tls_trace.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/version.c b/src/version.c new file mode 100644 index 00000000..e20ddd35 --- /dev/null +++ b/src/version.c @@ -0,0 +1,30 @@ +<<<<<<< HEAD:src/version.c +/* + * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +======= +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. +>>>>>>> 5fc13a8aefa3fb395f32927e35dda4210a3c1a23:tools/sm2view.c + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include "endian.h" + +const char *gmssl_version(void) +{ + return "GmSSL 3.0 alpha"; +} diff --git a/src/x509_algor.c b/src/x509_algor.c index 2bd7a65e..8aaf6f60 100644 --- a/src/x509_algor.c +++ b/src/x509_algor.c @@ -1,49 +1,22 @@ -/* +<<<<<<< HEAD +/* * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +======= +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. +>>>>>>> 5fc13a8aefa3fb395f32927e35dda4210a3c1a23 * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include @@ -54,73 +27,339 @@ #include -static const uint32_t DER_sm3[] = {1, 2, 156, 10197, 1, 401}; -static const uint32_t DER_md5[] = {1, 2, 840, 113549, 2, 5}; -static const uint32_t DER_sha1[] = {1, 3, 14, 3, 2, 26}; -static const uint32_t DER_sha256[] = {2, 16, 840, 1, 101, 3, 4, 2, 1}; -static const uint32_t DER_sha384[] = {2, 16, 840, 1, 101, 3, 4, 2, 2}; -static const uint32_t DER_sha512[] = {2, 16, 840, 1, 101, 3, 4, 2, 3}; -static const uint32_t DER_sha224[] = {2, 16, 840, 1, 101, 3, 4, 2, 4}; - -static struct { - int oid; +typedef struct { + int algor; char *name; const uint32_t *nodes; size_t nodes_count; -} digest_table[] = { - { OID_sm3, "sm3", DER_sm3, sizeof(DER_sm3)/sizeof(int) }, - { OID_md5, "md5", DER_md5, sizeof(DER_md5)/sizeof(int) }, - { OID_sha1, "sha1", DER_sha1, sizeof(DER_sha1)/sizeof(int) }, - { OID_sha224, "sha224", DER_sha224, sizeof(DER_sha224)/sizeof(int) }, - { OID_sha256, "sha256", DER_sha256, sizeof(DER_sha256)/sizeof(int) }, - { OID_sha384, "sha384", DER_sha384, sizeof(DER_sha384)/sizeof(int) }, - { OID_sha512, "sha512", DER_sha512, sizeof(DER_sha512)/sizeof(int) }, + int has_params; +} X509_ALGOR_INFO; + + +static const uint32_t oid_sm3[] = {1, 2, 156, 10197, 1, 401}; +static const uint32_t oid_md5[] = {1, 2, 840, 113549, 2, 5}; +static const uint32_t oid_sha1[] = {1, 3, 14, 3, 2, 26}; +static const uint32_t oid_sha256[] = {2, 16, 840, 1, 101, 3, 4, 2, 1}; +static const uint32_t oid_sha384[] = {2, 16, 840, 1, 101, 3, 4, 2, 2}; +static const uint32_t oid_sha512[] = {2, 16, 840, 1, 101, 3, 4, 2, 3}; +static const uint32_t oid_sha224[] = {2, 16, 840, 1, 101, 3, 4, 2, 4}; + +static X509_ALGOR_INFO x509_digest_algors[] = { + { OID_sm3, "sm3", oid_sm3, sizeof(oid_sm3)/sizeof(int), 0 }, + { OID_md5, "md5", oid_md5, sizeof(oid_md5)/sizeof(int), 0 }, + { OID_sha1, "sha1", oid_sha1, sizeof(oid_sha1)/sizeof(int), 0 }, + { OID_sha224, "sha224", oid_sha224, sizeof(oid_sha224)/sizeof(int), 0 }, + { OID_sha256, "sha256", oid_sha256, sizeof(oid_sha256)/sizeof(int), 0 }, + { OID_sha384, "sha384", oid_sha384, sizeof(oid_sha384)/sizeof(int), 0 }, + { OID_sha512, "sha512", oid_sha512, sizeof(oid_sha512)/sizeof(int), 0 }, }; -const char *x509_digest_algor_name(int oid) +static const int x509_digest_algors_count = + sizeof(x509_digest_algors)/sizeof(x509_digest_algors[0]); + +const char *x509_digest_algor_name(int algor) { int i; - for (i = 0; i < sizeof(digest_table)/sizeof(digest_table[0]); i++) { - if (oid == digest_table[i].oid) { - return digest_table[i].name; + for (i = 0; i < x509_digest_algors_count; i++) { + if (algor == x509_digest_algors[i].algor) { + return x509_digest_algors[i].name; } } return NULL; } -int x509_digest_algor_to_der(int oid, uint8_t **out, size_t *outlen) +int x509_digest_algor_from_name(const char *name) { - size_t len; + int i; + for (i = 0; i < x509_digest_algors_count; i++) { + if (strcmp(name, x509_digest_algors[i].name) == 0) { + return x509_digest_algors[i].algor; + } + } + return OID_undef; +} - if (oid != OID_sm3) { +int x509_digest_algor_to_der(int algor, uint8_t **out, size_t *outlen) +{ + size_t len = 0; + const uint32_t *nodes = NULL; + size_t nodes_count; + int i; + + for (i = 0; i < x509_digest_algors_count; i++) { + if (algor == x509_digest_algors[i].algor) { + nodes = x509_digest_algors[i].nodes; + nodes_count = x509_digest_algors[i].nodes_count; + break; + } + } + if (!nodes) { error_print(); return -1; } - if (asn1_object_identifier_to_der(oid, NULL, 0, NULL, &len) != 1 + + if (asn1_object_identifier_to_der(OID_undef, nodes, nodes_count, NULL, &len) != 1 || asn1_sequence_header_to_der(len, out, outlen) != 1 - || asn1_object_identifier_to_der(oid, NULL, 0, out, outlen) != 1) { + || asn1_object_identifier_to_der(OID_undef, nodes, nodes_count, out, outlen) != 1) { error_print(); return -1; } return 1; } -int x509_digest_algor_from_der(int *oid, uint32_t *nodes, size_t *nodes_count, +int x509_digest_algor_from_der(int *algor, uint32_t *nodes, size_t *nodes_count, const uint8_t **in, size_t *inlen) { int ret; const uint8_t *data; size_t datalen; + int i; if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { if (ret < 0) error_print(); return -1; } - if (asn1_object_identifier_from_der(oid, nodes, nodes_count, &data, &datalen) != 1) { + if (asn1_object_identifier_from_der(NULL, nodes, nodes_count, &data, &datalen) != 1 + || asn1_length_is_zero(datalen) != 1) { error_print(); return -1; } - if (*oid != OID_undef && *oid != OID_sm3) { + + for (i = 0; i < x509_digest_algors_count; i++) { + if (*nodes_count == x509_digest_algors[i].nodes_count + && memcmp(nodes, x509_digest_algors[i].nodes, (*nodes_count) * sizeof(int)) == 0) { + *algor = x509_digest_algors[i].algor; + return 1; + } + } + *algor = OID_undef; + error_print(); + return -1; +} + + +static uint32_t oid_sm4_cbc[] = {1, 2, 156, 10197, 1, 104, 2}; +static uint32_t oid_aes128_cbc[] = {2, 16, 840, 1, 101, 3, 4, 1, 2}; +static uint32_t oid_aes192_cbc[] = {2, 16, 840, 1, 101, 3, 4, 1, 22}; +static uint32_t oid_aes256_cbc[] = {2, 16, 840, 1, 101, 3, 4, 1, 42}; + +static const X509_ALGOR_INFO x509_encryption_algors[] = { + { OID_sm4_cbc, "sm4-cbc", oid_sm4_cbc, sizeof(oid_sm4_cbc)/sizeof(int), 1 }, + { OID_aes128_cbc, "aes128-cbc", oid_aes128_cbc, sizeof(oid_aes128_cbc)/sizeof(int), 1 }, + { OID_aes192_cbc, "aes192-cbc", oid_aes192_cbc, sizeof(oid_aes192_cbc)/sizeof(int), 1 }, + { OID_aes256_cbc, "aes256-cbc", oid_aes256_cbc, sizeof(oid_aes256_cbc)/sizeof(int), 1 }, +}; + +static const int x509_encryption_algors_count = + sizeof(x509_encryption_algors)/sizeof(x509_encryption_algors[0]); + +const char *x509_encryption_algor_name(int algor) +{ + int i; + for (i = 0; i < x509_encryption_algors_count; i++) { + if (algor == x509_encryption_algors[i].algor) { + return x509_encryption_algors[i].name; + } + } + return NULL; +} + +int x509_encryption_algor_from_name(const char *name) +{ + int i; + for (i = 0; i < x509_encryption_algors_count; i++) { + if (strcmp(name, x509_encryption_algors[i].name) == 0) { + return x509_encryption_algors[i].algor; + } + } + return 0; +} + +int x509_encryption_algor_to_der(int algor, const uint8_t *iv, size_t ivlen, + uint8_t **out, size_t *outlen) +{ + size_t len = 0; + const uint32_t *nodes = NULL; + size_t nodes_count; + int i; + + for (i = 0; i < x509_encryption_algors_count; i++) { + if (algor == x509_encryption_algors[i].algor) { + nodes = x509_encryption_algors[i].nodes; + nodes_count = x509_encryption_algors[i].nodes_count; + break; + } + } + if (i >= x509_encryption_algors_count ) { + error_print(); + return -1; + } + + if (asn1_object_identifier_to_der(OID_undef, nodes, nodes_count, NULL, &len) != 1 + || asn1_octet_string_to_der(iv, ivlen, NULL, &len) != 1 + || asn1_sequence_header_to_der(len, out, outlen) != 1 + || asn1_object_identifier_to_der(OID_undef, nodes, nodes_count, out, outlen) != 1 + || asn1_octet_string_to_der(iv, ivlen, out, outlen) != 1) { + error_print(); + return -1; + } + return 1; +} + +int x509_encryption_algor_from_der(int *algor, uint32_t *nodes, size_t *nodes_count, + const uint8_t **iv, size_t *ivlen, + const uint8_t **in, size_t *inlen) +{ + int ret; + const uint8_t *data; + size_t datalen; + int i; + + if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { + if (ret < 0) error_print(); + return ret; + } + if (asn1_object_identifier_from_der(NULL, nodes, nodes_count, &data, &datalen) != 1 + || asn1_octet_string_from_der(iv, ivlen, &data, &datalen) != 1 + || asn1_length_is_zero(datalen) != 1) { + error_print(); + return -1; + } + if (!(*iv) || *ivlen != 16) { + error_print(); + return -1; + } + for (i = 0; i < x509_encryption_algors_count; i++) { + if (*nodes_count == x509_encryption_algors[i].nodes_count + && memcmp(nodes, x509_encryption_algors[i].nodes, (*nodes_count) * sizeof(int)) == 0) { + *algor = x509_encryption_algors[i].algor; + return 1; + } + } + + *algor = OID_undef; + error_print(); + return -1; +} + + +static uint32_t oid_sm2sign_with_sm3[] = {1, 2, 156, 10197, 1, 501}; +static uint32_t oid_rsasign_with_sm3[] = {1, 2, 156, 10197, 1, 504}; +static uint32_t oid_ecdsa_with_sha1[] = {1, 2, 840, 10045, 4, 1}; +static uint32_t oid_ecdsa_with_sha224[] = {1, 2, 840, 10045, 4, 3, 1}; +static uint32_t oid_ecdsa_with_sha256[] = {1, 2, 840, 10045, 4, 3, 2}; +static uint32_t oid_ecdsa_with_sha384[] = {1, 2, 840, 10045, 4, 3, 3}; +static uint32_t oid_ecdsa_with_sha512[] = {1, 2, 840, 10045, 4, 3, 4}; +static uint32_t oid_rsasign_with_sha1[] = {1, 2,840, 113549, 1, 1, 5}; +static uint32_t oid_rsasign_with_sha224[] = {1, 2, 840, 113549, 1, 1, 14}; +static uint32_t oid_rsasign_with_sha256[] = {1, 2, 840, 113549, 1, 1, 11}; +static uint32_t oid_rsasign_with_sha384[] = {1, 2, 840, 113549, 1, 1, 12}; +static uint32_t oid_rsasign_with_sha512[] = {1, 2, 840, 113549, 1, 1, 13}; + +static const X509_ALGOR_INFO x509_sign_algors[] = { + { OID_sm2sign_with_sm3, "sm2sign-with-sm3", oid_sm2sign_with_sm3, sizeof(oid_sm2sign_with_sm3)/sizeof(int), 0 }, + { OID_rsasign_with_sm3, "rsasign-with-sm3", oid_rsasign_with_sm3, sizeof(oid_rsasign_with_sm3)/sizeof(int), 1 }, + { OID_ecdsa_with_sha1, "ecdsa-with-sha1", oid_ecdsa_with_sha1, sizeof(oid_ecdsa_with_sha1)/sizeof(int), 0 }, + { OID_ecdsa_with_sha224, "ecdsa-with-sha224", oid_ecdsa_with_sha224, sizeof(oid_ecdsa_with_sha224)/sizeof(int), 0} , + { OID_ecdsa_with_sha256, "ecdsa-with-sha256", oid_ecdsa_with_sha256, sizeof(oid_ecdsa_with_sha256)/sizeof(int), 0}, + { OID_ecdsa_with_sha384, "ecdsa-with-sha384", oid_ecdsa_with_sha384, sizeof(oid_ecdsa_with_sha384)/sizeof(int), 0 }, + { OID_ecdsa_with_sha512, "ecdsa-with-sha512", oid_ecdsa_with_sha512, sizeof(oid_ecdsa_with_sha512)/sizeof(int), 0 }, + { OID_rsasign_with_sha1, "sha1WithRSAEncryption", oid_rsasign_with_sha1, sizeof(oid_rsasign_with_sha1)/sizeof(int), 0 }, + { OID_rsasign_with_sha224, "sha224WithRSAEncryption", oid_rsasign_with_sha224, sizeof(oid_rsasign_with_sha224)/sizeof(int), 1 }, + { OID_rsasign_with_sha256, "sha256WithRSAEncryption", oid_rsasign_with_sha256, sizeof(oid_rsasign_with_sha256)/sizeof(int), 1 }, + { OID_rsasign_with_sha384, "sha384WithRSAEncryption", oid_rsasign_with_sha384, sizeof(oid_rsasign_with_sha384)/sizeof(int), 1 }, + { OID_rsasign_with_sha512, "sha512WithRSAEncryption", oid_rsasign_with_sha512, sizeof(oid_rsasign_with_sha512)/sizeof(int), 1 }, +}; + +static const int x509_sign_algors_count = + sizeof(x509_sign_algors)/sizeof(x509_sign_algors[0]); + +const char *x509_signature_algor_name(int algor) +{ + int i; + for (i = 0; i < x509_sign_algors_count; i++) { + if (algor == x509_sign_algors[i].algor) { + return x509_sign_algors[i].name; + } + } + return NULL; +} + +int x509_signature_algor_from_name(const char *name) +{ + int i; + for (i = 0; i < x509_sign_algors_count; i++) { + if (strcmp(name, x509_sign_algors[i].name) == 0) { + return x509_sign_algors[i].algor; + } + } + return OID_undef; +} + +int x509_signature_algor_to_der(int algor, uint8_t **out, size_t *outlen) +{ + size_t len = 0; + const uint32_t *nodes; + size_t nodes_count; + int has_null_obj; + int i; + + for (i = 0; i < x509_sign_algors_count; i++) { + if (algor == x509_sign_algors[i].algor) { + nodes = x509_sign_algors[i].nodes; + nodes_count = x509_sign_algors[i].nodes_count; + has_null_obj = x509_sign_algors[i].has_params; + break; + } + } + if (i >= x509_sign_algors_count) { + error_print(); + return -1; + } + + if (asn1_object_identifier_to_der(OID_undef, nodes, nodes_count, NULL, &len) != 1 + || (has_null_obj && asn1_null_to_der(NULL, &len) != 1) + || asn1_sequence_header_to_der(len, out, outlen) != 1 + || asn1_object_identifier_to_der(OID_undef, nodes, nodes_count, out, outlen) != 1 + || (has_null_obj && asn1_null_to_der(out, outlen) != 1)) { + error_print(); + return -1; + } + return 1; +} + +int x509_signature_algor_from_der(int *algor, uint32_t *nodes, size_t *nodes_count, + const uint8_t **in, size_t *inlen) +{ + int ret; + const uint8_t *data; + size_t datalen; + int has_null_obj; + int i; + + if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { + if (ret < 0) error_print(); + if (ret == 0) error_print(); + return ret; + } + if (asn1_object_identifier_from_der(algor, nodes, nodes_count, &data, &datalen) != 1) { + error_print(); + return -1; + } + for (i = 0; i < x509_sign_algors_count; i++) { + if (*nodes_count == x509_sign_algors[i].nodes_count + && memcmp(nodes, x509_sign_algors[i].nodes, (*nodes_count) * sizeof(int)) == 0) { + *algor = x509_sign_algors[i].algor; + has_null_obj = x509_sign_algors[i].has_params; + break; + } + } + if (i >= x509_sign_algors_count) { + error_print(); + return -1; + } + + if (has_null_obj && asn1_null_from_der(&data, &datalen) != 1) { error_print(); return -1; } @@ -131,201 +370,74 @@ int x509_digest_algor_from_der(int *oid, uint32_t *nodes, size_t *nodes_count, return 1; } +/* +from rfc 3560: +RSAES-OAEP-params ::= SEQUENCE { + hashFunc [0] AlgorithmIdentifier DEFAULT sha1Identifier, + maskGenFunc [1] AlgorithmIdentifier DEFAULT mgf1SHA1Identifier, + pSourceFunc [2] AlgorithmIdentifier DEFAULT -static uint32_t sm4_cbc_nodes[] = { 1, 2, 156, 10197, 1, 104, 2 }; -static size_t sm4_cbc_nodes_count = sizeof(sm4_cbc_nodes)/sizeof(sm4_cbc_nodes[0]); +SM2公钥加密算法参数默认为SM3,本实现在to_der时不编码参数 +在from_der时,将参数直接返回给应用,不做处理 +*/ +static uint32_t oid_sm2encrypt[] = {1, 2, 156, 10197, 1, 301, 2}; +static uint32_t oid_rsa_encryption[] = {1, 2, 840, 113549, 1, 1, 1}; +static uint32_t oid_rsaes_oaep[] = {1, 2, 840, 113549, 1, 1, 7}; -int x509_encryption_algor_to_der(int cipher, const uint8_t *iv, size_t ivlen, - uint8_t **out, size_t *outlen) +static const X509_ALGOR_INFO x509_pke_algors[] = { + { OID_sm2encrypt, "sm2encrypt", oid_sm2encrypt, sizeof(oid_sm2encrypt)/sizeof(int) }, + { OID_rsa_encryption, "rsaEncryption", oid_rsa_encryption, sizeof(oid_rsa_encryption)/sizeof(int) }, + { OID_rsaes_oaep, "rsaesOAEP", oid_rsaes_oaep, sizeof(oid_rsaes_oaep)/sizeof(int) }, +}; + +static const int x509_pke_algors_count = + sizeof(x509_pke_algors)/sizeof(x509_pke_algors[0]); + +const char *x509_public_key_encryption_algor_name(int algor) { - size_t len = 0; - - if (cipher != OID_sm4_cbc || ivlen != 16) { - error_print(); - return -1; - } - if (asn1_object_identifier_to_der(OID_undef, sm4_cbc_nodes, sm4_cbc_nodes_count, NULL, &len) != 1 - || asn1_octet_string_to_der(iv, ivlen, NULL, &len) != 1 - || asn1_sequence_header_to_der(len, out, outlen) != 1 - || asn1_object_identifier_to_der(OID_undef, sm4_cbc_nodes, sm4_cbc_nodes_count, out, outlen) != 1 - || asn1_octet_string_to_der(iv, ivlen, out, outlen) != 1) { - error_print(); - return -1; - } - return 1; -} - -const char *x509_encryption_algor_name(int algor) -{ - switch (algor) { - case OID_sm4_cbc: return "sm4-cbc"; + int i; + for (i = 0; i < x509_pke_algors_count; i++) { + if (algor == x509_pke_algors[i].algor) { + return x509_pke_algors[i].name; + } } return NULL; } - -int x509_encryption_algor_from_der(int *algor, uint32_t nodes[32], size_t *nodes_count, - const uint8_t **iv, size_t *ivlen, - const uint8_t **in, size_t *inlen) +int x509_public_key_encryption_algor_from_name(const char *name) { - int ret; - const uint8_t *data; - size_t datalen; - - if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { - if (ret < 0) error_print(); - return ret; - } - if (asn1_object_identifier_from_der(algor, nodes, nodes_count, &data, &datalen) != 1 - || asn1_octet_string_from_der(iv, ivlen, &data, &datalen) != 1 - || datalen > 0) { - error_print(); - return -1; - } - if (*algor == OID_undef) { - if (*nodes_count == sm4_cbc_nodes_count - && memcmp(nodes, sm4_cbc_nodes, sizeof(sm4_cbc_nodes)) == 0) { - *algor = OID_sm4_cbc; - } else { - size_t i; - error_puts("unknown cipher oid :"); - for (i = 0; i < *nodes_count; i++) { - fprintf(stderr, " %d", nodes[i]); - } - fprintf(stderr, "\n"); - return -1; + int i; + for (i = 0; i < x509_pke_algors_count; i++) { + if (strcmp(name, x509_pke_algors[i].name) == 0) { + return x509_pke_algors[i].algor; } } - - // FIXME: 检查ivlen - return 1; + return OID_undef; } -int x509_signature_algor_to_der(int oid, uint8_t **out, size_t *outlen) -{ - size_t len = 0; - int has_null_obj = 0; - - switch (oid) { - // ECDSA/SM2 parameters MUST be omitted - //case OID_ecdsa_with_sha1: - //case OID_ecdsa_with_sha224 - //case OID_ecdsa_with_sha256: - //case OID_ecdsa_with_sha384: - //case OID_ecdsa_with_sha512: - case OID_sm2sign_with_sm3: - has_null_obj = 0; - break; - // RSA parameters MUST be ASN1_NULL - //case OID_sha1WithRSAEncryption: - //case OID_sha224WithRSAEncryption: - //case OID_sha256WithRSAEncryption: - //case OID_sha384WithRSAEncryption: - //case OID_sha512WithRSAEncryption: - case OID_rsasign_with_sm3: - has_null_obj = 1; - break; - default: - error_print(); - return -1; - } - - if (asn1_object_identifier_to_der(oid, NULL, 0, NULL, &len) != 1) { - error_print(); - return -1; - } - - if (has_null_obj) { - if (asn1_null_to_der(NULL, &len) != 1) { - error_print(); - return -1; - } - } - - if (asn1_sequence_header_to_der(len, out, outlen) != 1 - || asn1_object_identifier_to_der(oid, NULL, 0, out, outlen) != 1) { - error_print(); - return -1; - } - - if (has_null_obj) { - if (asn1_null_to_der(out, outlen) != 1) { - error_print(); - return -1; - } - } - - return 1; -} - -int x509_signature_algor_from_der(int *algor, uint32_t nodes[32], size_t nodes_count, - const uint8_t **in, size_t *inlen) -{ - int ret; - const uint8_t *data; - size_t datalen; - int has_null_obj; - - if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { - return ret; - } - if (asn1_object_identifier_from_der(algor, nodes, &nodes_count, &data, &datalen) != 1) { - error_print(); - return -1; - } - if ((has_null_obj = asn1_null_from_der(&data, &datalen)) < 0) { - error_print(); - return -1; - } - if (datalen > 0) { - error_print_msg("datalen = %zu", datalen); - error_print(); - return -1; - } - - switch (*algor) { - //case OID_ecdsa_with_sha1: - //case OID_ecdsa_with_sha224 - //case OID_ecdsa_with_sha256: - //case OID_ecdsa_with_sha384: - //case OID_ecdsa_with_sha512: - case OID_sm2sign_with_sm3: - if (has_null_obj) { - fprintf(stderr, "WARN: %s %d: AlgorithmIdentifier.parameters SHOULD be omitted for ECDSA/SM2\n", __FILE__, __LINE__); - } - break; - //case OID_sha1WithRSAEncryption: - //case OID_sha224WithRSAEncryption: - //case OID_sha256WithRSAEncryption: - //case OID_sha384WithRSAEncryption: - //case OID_sha512WithRSAEncryption: - case OID_rsasign_with_sm3: - if (!has_null_obj) { - fprintf(stderr, "WARN: %s %d\n: parameters SHOULD be NULL object for RSA", __FILE__, __LINE__); - } - break; - default: - // print unknown OID nodes - error_print(); - return -1; - } - - return 1; -} - - -const uint32_t DER_sm2encrypt[] = {1,2,156,10197,1,301,2}; - int x509_public_key_encryption_algor_to_der(int algor, uint8_t **out, size_t *outlen) { size_t len = 0; + const uint32_t *nodes; + size_t nodes_count; + int i; - if (asn1_object_identifier_to_der(OID_undef, DER_sm2encrypt, - sizeof(DER_sm2encrypt)/sizeof(DER_sm2encrypt[0]), NULL, &len) != 1 + for (i = 0; i < x509_pke_algors_count; i++) { + if (algor == x509_pke_algors[i].algor) { + nodes = x509_pke_algors[i].nodes; + nodes_count = x509_pke_algors[i].nodes_count; + break; + } + } + if (i >= x509_pke_algors_count) { + error_print(); + return -1; + } + + if (asn1_object_identifier_to_der(OID_undef, nodes, nodes_count, NULL, &len) != 1 || asn1_sequence_header_to_der(len, out, outlen) != 1 - || asn1_object_identifier_to_der(OID_undef, DER_sm2encrypt, - sizeof(DER_sm2encrypt)/sizeof(DER_sm2encrypt[0]), out, outlen) != 1) { + || asn1_object_identifier_to_der(OID_undef, nodes, nodes_count, out, outlen) != 1) { error_print(); return -1; } @@ -339,15 +451,31 @@ int x509_public_key_encryption_algor_from_der(int *algor, uint32_t *nodes, size_ int ret; const uint8_t *data; size_t datalen; + int i; if ((ret = asn1_sequence_from_der(&data, &datalen, in, inlen)) != 1) { if (ret < 0) error_print(); return ret; } - if (asn1_object_identifier_from_der(algor, nodes, nodes_count, &data, &datalen) != 1) { + if (asn1_object_identifier_from_der(NULL, nodes, nodes_count, &data, &datalen) != 1) { error_print(); return -1; } - // FIXME: 我们需要一个读取完整obj的函数 + + for (i = 0; i < x509_pke_algors_count; i++) { + if (*nodes_count == x509_pke_algors[i].nodes_count + && memcmp(nodes, x509_pke_algors[i].nodes, (*nodes_count) * sizeof(int)) == 0) { + *algor = x509_pke_algors[i].algor; + break; + } + } + if (i >= x509_pke_algors_count) { + error_print(); + return -1; + } + if (datalen) { + *params = data; + *params_len = datalen; + } return 1; } diff --git a/src/x509_asn1.c b/src/x509_asn1.c index 7cb6fbeb..2c1bbb80 100644 --- a/src/x509_asn1.c +++ b/src/x509_asn1.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include @@ -79,7 +47,7 @@ int x509_version_to_der(int version, uint8_t **out, size_t *outlen) case X509_version_v3: break; default: - error_puts("invalid version"); + error_print_msg("invalid version %d\n", version); return -1; } if (asn1_int_to_der(version, NULL, &len) != 1 @@ -797,7 +765,7 @@ int x509_extension_from_der(int *oid, uint32_t *nodes, size_t *nodes_count, if (x509_extension_oid_from_der(oid, nodes, nodes_count, &seq, &seqlen) != 1 // FIXME: 这里检查OID应该是从一个子集里面检索 || asn1_boolean_from_der(is_critical, &seq, &seqlen) < 0 || asn1_octet_string_from_der(data, datalen, &seq, &seqlen) != 1 - || seqlen > 0) { + || asn1_length_is_zero(seqlen) != 1) { error_print(); return -1; } @@ -832,6 +800,8 @@ int x509_extension_print(FILE *fp, int oid, const uint32_t *nodes, size_t nodes_ case OID_ce_basicConstraints: return x509_basic_constraints_print(fp, data, datalen, format, indent); case OID_ce_keyUsage: return x509_key_usage_print(fp, data, datalen, format, indent); case OID_ce_subjectKeyIdentifier: return x509_subject_key_identifier_print(fp, data, datalen, format, indent); + case OID_ce_extKeyUsage: return x509_ext_key_usage_print(fp, data, datalen, format, indent); + case OID_ce_policyConstraints: return x509_policy_constraints_print(fp, data, datalen, format, indent); default: format_bytes(fp, format, indent, "extnValue : ", data, datalen); } @@ -881,7 +851,7 @@ int x509_extensions_from_der(X509_EXTENSIONS *a, const uint8_t **in, size_t *inl return ret; } if (asn1_sequence_copy_from_der(512, a->data, &a->datalen, &data, &datalen) != 1 - || datalen > 0) { + || asn1_length_is_zero(datalen) != 1) { error_print(); return -1; } @@ -1005,6 +975,12 @@ int x509_tbs_certificate_from_der(X509_TBS_CERTIFICATE *a, const uint8_t **in, s if (ret < 0) error_print(); return ret; } + + memset(a, 0, sizeof(*a)); + + size_t issuer_unique_id_nbits; + size_t subject_unique_id_nbits; + if (x509_version_from_der(&a->version, &data, &datalen) != 1 || asn1_integer_from_der(&serial_number, &a->serial_number_len, &data, &datalen) != 1 || x509_signature_algor_from_der(&a->signature_algor, nodes, &nodes_count, &data, &datalen) != 1 @@ -1012,21 +988,31 @@ int x509_tbs_certificate_from_der(X509_TBS_CERTIFICATE *a, const uint8_t **in, s || x509_validity_from_der(&a->validity, &data, &datalen) != 1 || x509_name_from_der(&a->subject, &data, &datalen) != 1 || x509_public_key_info_from_der(&a->subject_public_key_info, &data, &datalen) != 1 - || asn1_implicit_bit_string_from_der(1, &issuer_unique_id, &a->issuer_unique_id_len, &data, &datalen) < 0 - || asn1_implicit_bit_string_from_der(2, &subject_unique_id, &a->subject_unique_id_len, &data, &datalen) < 0 + || asn1_implicit_bit_string_from_der(1, &issuer_unique_id, &issuer_unique_id_nbits, &data, &datalen) < 0 + || asn1_implicit_bit_string_from_der(2, &subject_unique_id, &subject_unique_id_nbits, &data, &datalen) < 0 || (is_ext = x509_extensions_from_der(&a->extensions, &data, &datalen)) < 0 - || datalen > 0) { + || asn1_length_is_zero(datalen) != 1) { error_print(); - if (datalen > 0) error_print(); return -1; } + // FIXME: 应该提供了检查函数,可以返回错误行数 if (a->serial_number_len > 20 - || a->issuer_unique_id_len > 64 - || a->subject_unique_id_len > 64) { + || issuer_unique_id_nbits != 32 * 8 + || subject_unique_id_nbits != 32 * 8) { + error_print(); return -1; } + + a->issuer_unique_id_len = issuer_unique_id_nbits/8; + a->subject_unique_id_len = subject_unique_id_nbits/8; + + + // asn1_implicit_bit_string_from_der 返回的是比特长度! + // 应该改变 issue + + // FIXME: 这几个都应该用copy的方式 memcpy(a->serial_number, serial_number, a->serial_number_len); if (issuer_unique_id) { @@ -1087,10 +1073,24 @@ int x509_certificate_from_der(X509_CERTIFICATE *a, const uint8_t **in, size_t *i return ret; } memset(a, 0, sizeof(X509_CERTIFICATE)); - if (x509_tbs_certificate_from_der(&a->tbs_certificate, &data, &datalen) != 1 - || x509_signature_algor_from_der(&a->signature_algor, nodes, &nodes_count, &data, &datalen) != 1 - || asn1_bit_string_from_der(&sig, &sig_nbits, &data, &datalen) != 1 - || datalen > 0) { + if (x509_tbs_certificate_from_der(&a->tbs_certificate, &data, &datalen) != 1) { + error_print(); + return -1; + } + if (x509_signature_algor_from_der(&a->signature_algor, nodes, &nodes_count, &data, &datalen) != 1) { + error_print(); + int i; + for (i = 0; i < nodes_count; i++) { + printf("%d ", (int)nodes[i]); + } + printf("\n"); + return -1; + } + if (asn1_bit_string_from_der(&sig, &sig_nbits, &data, &datalen) != 1) { + error_print(); + return -1; + } + if (asn1_length_is_zero(datalen) != 1) { error_print(); return -1; } @@ -1237,13 +1237,27 @@ int x509_cert_request_info_from_der(X509_CERT_REQUEST_INFO *a, const uint8_t **i || x509_name_from_der(&a->subject, &data, &datalen) != 1 || x509_public_key_info_from_der(&a->subject_public_key_info, &data, &datalen) != 1 || asn1_implicit_from_der(0, &attrs, &attrslen, &data, &datalen) < 0 - || datalen > 0) { + || asn1_length_is_zero(datalen) != 1) { error_print(); return -1; } return 1; } +int x509_cert_request_info_print(FILE *fp, const X509_CERT_REQUEST_INFO *a, int format, int indent) +{ + format_print(fp, format, indent, "CertificationRequestInfo\n"); + indent += 4; + format_print(fp, format, indent, "version: %s (%d)\n", x509_version_name(a->version), a->version); + format_print(fp, format, indent, "subject\n"); + x509_name_print(fp, &a->subject, format, indent+4); + format_print(fp, format, indent, "subjectPublicKeyInfo\n"); + x509_public_key_info_print(fp, &a->subject_public_key_info, format, indent+4); + + // FIXME: attributes 没有处理 + return 1; +} + int x509_cert_request_to_der(const X509_CERT_REQUEST *a, uint8_t **out, size_t *outlen) { size_t len = 0; @@ -1277,12 +1291,10 @@ int x509_cert_request_from_der(X509_CERT_REQUEST *a, const uint8_t **in, size_t if (x509_cert_request_info_from_der(&a->req_info, &data, &datalen) != 1 || x509_signature_algor_from_der(&a->signature_algor, nodes, &nodes_count, &data, &datalen) != 1 || x509_signature_copy_from_der(128, a->signature, &a->signature_len, &data, &datalen) != 1 - || datalen > 0) { + || asn1_length_is_zero(datalen) != 1) { error_print(); return -1; } - a->signature_len = siglen * 8; - memcpy(a->signature, sig, a->signature_len); return 1; } @@ -1314,7 +1326,7 @@ int x509_cert_request_from_pem(X509_CERT_REQUEST *a, FILE *fp) return -1; } if (x509_cert_request_from_der(a, &cp, &len) != 1 - || len > 0) { + || asn1_length_is_zero(len) != 1) { error_print(); return -1; } @@ -1324,15 +1336,12 @@ int x509_cert_request_from_pem(X509_CERT_REQUEST *a, FILE *fp) int x509_cert_request_print(FILE *fp, const X509_CERT_REQUEST *a, int format, int indent) { size_t i; - fprintf(fp, "version = %s\n", x509_version_name(a->req_info.version)); - x509_name_print(fp, &a->req_info.subject, 0, 0); - x509_public_key_info_print(fp, &a->req_info.subject_public_key_info, 0, 0); - fprintf(fp, "SignatureAlgorithm = %s\n", asn1_object_identifier_name(a->signature_algor)); - fprintf(fp, "Signature = "); - for (i = 0; i < a->signature_len; i++) { - fprintf(fp, "%02x", a->signature[i]); - } - fprintf(fp, "\n"); + + format_print(fp, format, indent, "CertificationRequest\n"); + indent += 4; + x509_cert_request_info_print(fp, &a->req_info, format, indent); + format_print(fp, format, indent, "signatureAlgorithm: %s\n", asn1_object_identifier_name(a->signature_algor)); + format_bytes(fp, format, indent, "signature: ", a->signature, a->signature_len); return 1; } diff --git a/src/x509_crl.c b/src/x509_crl.c index eb01a803..568e3a22 100644 --- a/src/x509_crl.c +++ b/src/x509_crl.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/x509_ext.c b/src/x509_ext.c index a50f93e9..a49a677f 100644 --- a/src/x509_ext.c +++ b/src/x509_ext.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ @@ -1039,7 +1007,29 @@ KeyUsage ::= BIT STRING { /* -4 CertificatePolicies ::= SEQUENCE SIZE (1..MAX) OF PolicyInformation +4 +CertificatePolicies ::= SEQUENCE SIZE (1..MAX) OF PolicyInformation + +PolicyInformation ::= SEQUENCE { + policyIdentifier OBJECT IDENTIFIER, + policyQualifiers SEQUENCE SIZE (1..MAX) OF + PolicyQualifierInfo OPTIONAL } + +PolicyQualifierInfo ::= SEQUENCE { + policyQualifierId OBJECT IDENTIFIER, + qualifier ANY DEFINED BY policyQualifierId } + +Qualifier ::= CHOICE { + cPSuri IA5String, + userNotice UserNotice } + +UserNotice ::= SEQUENCE { + noticeRef NoticeReference OPTIONAL, + explicitText DisplayText OPTIONAL } + +NoticeReference ::= SEQUENCE { + organization DisplayText, + noticeNumbers SEQUENCE OF INTEGER } 看来这是一个非常复杂的扩展,可能很难通过简单的接口去设置。 @@ -1047,6 +1037,9 @@ KeyUsage ::= BIT STRING { 在解析的时候,可以有独立的函数将其解析成文本之类的可能更好 虽然这个扩展很复杂,但是我们的主要需求就是能够解析并转化为可显示的字符串 + +这个扩展在证书中确实是出现的,但是我们主要的目标还是显示这个扩展的内容 + */ @@ -1365,11 +1358,16 @@ int x509_policy_mapping_from_der( /* - ## 6 +## 6 - SubjectAltName ::= GeneralNames +SubjectAltName ::= GeneralNames GeneralNames 也是 SEQUENCE OF SEQUENCE + +提供证书主体的多个可替代的名字,如域名、IP地址、邮件地址等。 + + + */ @@ -1542,22 +1540,16 @@ int x509_basic_constraints_print(FILE *fp, const uint8_t *data, size_t datalen, return -1; } if (is_ca_cert >= 0) { - fprintf(fp, "cA : %s\n", is_ca_cert ? "true" : "false"); + + format_print(fp, format, indent, "cA : %s\n", is_ca_cert ? "true" : "false"); + } if (cert_chain_maxlen >= 0) { - fprintf(fp, "pathLenConstraint : %d\n", cert_chain_maxlen); + format_print(fp, format, indent, "pathLenConstraint : %d\n", cert_chain_maxlen); } return 1; } - - - - - - - - /* 10 GeneralSubtrees ::= SEQUENCE SIZE (1..MAX) OF GeneralSubtree @@ -1683,6 +1675,29 @@ PolicyConstraints ::= SEQUENCE { Conforming CAs MUST mark this extension as critical. */ + +int x509_policy_constraints_print(FILE *fp, const uint8_t *p, size_t len, int format, int indent) +{ + int require_explicit_policy = -1; + int inhibit_policy_mapping = -1; + if (x509_policy_constraints_from_der(&require_explicit_policy, &inhibit_policy_mapping, &p, &len) != 1) { + error_print(); + return -1; + } + format_print(fp, format, indent, "policyConstraints:\n"); + if (require_explicit_policy >= 0) { + format_print(fp, format, indent+4, "requireExplicitPolicy: %d\n", require_explicit_policy); + } + if (inhibit_policy_mapping >= 0) { + format_print(fp, format, indent+4, "inhibitPolicyMapping: %d\n", inhibit_policy_mapping); + } + if (len) { + error_print(); + return -1; + } + return 1; +} + int x509_policy_constraints_to_der(int require_explicit_policy, int inhibit_policy_mapping, uint8_t **out, size_t *outlen) { size_t len = 0; @@ -1745,15 +1760,52 @@ ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF OBJECT IDENTIFIER 解析的时候不可能只用oid来承接了,必须用带buffer的来承接 */ +int x509_ext_key_usage_print(FILE *fp, const uint8_t *p, size_t len, int format, int indent) +{ + const uint8_t *data; + size_t datalen; + + if (asn1_sequence_from_der(&data, &datalen, &p, &len) != 1) { + error_print(); + return -1; + } + format_print(fp, format, indent, "extKeyUsages:\n"); + while (datalen) { + int key_usage; + uint32_t nodes[32]; + size_t nodes_count; + size_t i; + + if (asn1_object_identifier_from_der(&key_usage, nodes, &nodes_count, &data, &datalen) != 1) { + error_print(); + return -1; + } + format_print(fp, format, indent + 4, "%s (", "unknown"); + for (i = 0; i < nodes_count - 1; i++) { + fprintf(fp, "%d.", nodes[i]); + } + fprintf(fp, "%d)\n", nodes[i]); + } + + if (len) { + error_print(); + return -1; + } + return 1; +} /* +## 13 CRLDistributionPoints + +SHOULD be non-critical + + 实际上我现在没有一个统一的方法去处理CHOICE类型的设置和解析 首先是否要给一个CHOICE类型设置一个新的对象,按照我们的设置,如果设置的话,就需要这个对象能够承载内部数据 -13 CRLDistributionPoints ::= SEQUENCE SIZE (1..MAX) OF DistributionPoint @@ -1966,7 +2018,7 @@ int x509_subject_key_identifier_print(FILE *fp, const uint8_t *data, size_t data error_print(); return -1; } - format_bytes(fp, format, indent, "", keyid, keyidlen); + format_bytes(fp, format, indent, "keyIdentifier: ", keyid, keyidlen); return 1; } diff --git a/src/x509_lib.c b/src/x509_lib.c index c4f31883..690f48c1 100644 --- a/src/x509_lib.c +++ b/src/x509_lib.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ /* diff --git a/src/zuc_core.c b/src/zuc_core.c index 068760c9..b45fb8a1 100644 --- a/src/zuc_core.c +++ b/src/zuc_core.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2015 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/zuc_eea.c b/src/zuc_eea.c index 089f1d90..4ff20ffe 100644 --- a/src/zuc_eea.c +++ b/src/zuc_eea.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2015 - 2019 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/src/zuc_eia.c b/src/zuc_eia.c index 73226957..8bbf0ca8 100644 --- a/src/zuc_eia.c +++ b/src/zuc_eia.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2015 - 2019 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/aestest.c b/tests/aestest.c index f7ae56c3..95a5dea0 100644 --- a/tests/aestest.c +++ b/tests/aestest.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/tests/asn1test.c b/tests/asn1test.c index 6a5884ab..f0e314fb 100644 --- a/tests/asn1test.c +++ b/tests/asn1test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/base64test.c b/tests/base64test.c index 97b0c69a..bae6e293 100644 --- a/tests/base64test.c +++ b/tests/base64test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/tests/block_ciphertest.c b/tests/block_ciphertest.c index 2887386f..81747f71 100644 --- a/tests/block_ciphertest.c +++ b/tests/block_ciphertest.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/chacha20test.c b/tests/chacha20test.c index d6076d9c..05001e0e 100644 --- a/tests/chacha20test.c +++ b/tests/chacha20test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/tests/cmstest.c b/tests/cmstest.c index 9342ae07..4bf8bcc1 100644 --- a/tests/cmstest.c +++ b/tests/cmstest.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include @@ -59,25 +27,512 @@ static int test_cms_data(void) { uint8_t data[20]; - uint8_t content_info[512]; - size_t content_info_len = sizeof(content_info); + uint8_t der[512]; + uint8_t *p = der; size_t len = 0; int i; memset(data, 'A', sizeof(data)); - - cms_content_info_set_data(content_info, &content_info_len, data, sizeof(data)); - cms_content_info_print(stdout, content_info, content_info_len, 0, 0); - return 1; + if (cms_content_info_to_der(CMS_data, data, sizeof(data), &p, &len) != 1 + || cms_content_info_print(stdout, der, len, 0, 0) != 1) { + error_print(); + return -1; + } + return 0; } +static int test_cms_enced_content_info(void) +{ + SM4_KEY sm4_key; + uint8_t key[16] = {0}; + uint8_t iv[16] = {0}; + uint8_t data[] = "Hello!"; + uint8_t buf[512]; + const uint8_t *cp = buf; + uint8_t *p = buf; + size_t len = 0; + int content_type; + uint8_t content[512] = {0}; + const uint8_t *shared_info1; + const uint8_t *shared_info2; + size_t content_len; + size_t shared_info1_len; + size_t shared_info2_len; + + sm4_set_encrypt_key(&sm4_key, key); + if (cms_enced_content_info_encrypt_to_der(&sm4_key, iv, + CMS_data, data, sizeof(data), + NULL, 0, NULL, 0, &p, &len) != 1) { + error_print(); + return -1; + } + + sm4_set_decrypt_key(&sm4_key, key); + if (cms_enced_content_info_decrypt_from_der(&sm4_key, &content_type, content, &content_len, + &shared_info1, &shared_info1_len, + &shared_info2, &shared_info2_len, + &cp, &len) != 1) { + error_print(); + return -1; + } + + printf("ContentType: %s\n", cms_content_type_name(content_type)); + printf("Content: %s\n", (char *)content); + printf("SharedInfo1: %s\n", (char *)shared_info1); + printf("SharedInfo2: %s\n", (char *)shared_info2); + return 0; +} + +static int test_cms_encrypt(void) +{ + uint8_t key[16]; + uint8_t msg[] = "Hello world!"; + uint8_t cbuf[512]; + uint8_t mbuf[512] = {0}; + size_t clen, mlen; + int content_type = 0; + const uint8_t *shared_info1 = NULL; + const uint8_t *shared_info2 = NULL; + size_t shared_info1_len, shared_info2_len; + + printf("%s()\n", __FUNCTION__); + + if (cms_encrypt(key, msg, sizeof(msg), cbuf, &clen) != 1) { + error_print(); + return -1; + } + cms_content_info_print(stdout, cbuf, clen, 0, 0); + + if (cms_decrypt(key, cbuf, clen, &content_type, mbuf, &mlen) != 1) { + error_print(); + return -1; + } + printf(" ContentType : %s\n", cms_content_type_name(content_type)); + printf(" Content: %s\n", mbuf); + return 0; +} + +static int test_cms_key_agreement_info(void) +{ + SM2_KEY sm2_key; + X509_CERTIFICATE cert; + FILE *key_fp = fopen("sign_key.pem", "r"); + FILE *cert_fp = fopen("sign_cert.pem", "r"); + uint8_t buf[512]; + uint8_t *p = buf; + const uint8_t *cp = buf; + size_t len = 0; + const uint8_t *id; + size_t idlen; + + if (sm2_private_key_from_pem(&sm2_key, key_fp) != 1) { + error_print(); + return -1; + } + if (x509_certificate_from_pem(&cert, cert_fp) != 1) { + error_print(); + return -1; + } + + if (cms_key_agreement_info_to_der(&sm2_key, &cert, (uint8_t *)"Alice", strlen("Alice"), &p, &len) != 1) { + error_print(); + return -1; + } + cms_key_agreement_info_print(stdout, buf, len, 0, 0); + if (cms_key_agreement_info_from_der(&sm2_key, &cert, &id, &idlen, &cp, &len) != 1 + || asn1_length_is_zero(len) != 1) { + error_print(); + return -1; + } + + return 0; +} + +static int test_cms_issuer_and_serial_number(void) +{ + FILE *cert_fp = fopen("sign_cert.pem", "r"); + X509_CERTIFICATE cert; + + X509_NAME issuer; + const X509_NAME *issuer_ptr; + const uint8_t *serial_number; + size_t serial_number_len; + const SM2_KEY *sm2_key; + + uint8_t buf[512]; + uint8_t *p = buf; + const uint8_t *cp = buf; + size_t len = 0; + + + if (x509_certificate_from_pem(&cert, cert_fp) != 1) { + error_print(); + return -1; + } + + if (cms_issuer_and_serial_number_from_certificate(&issuer_ptr, + &serial_number, &serial_number_len, &cert) != 1) { + error_print(); + return -1; + } + + if (cms_issuer_and_serial_number_to_der(issuer_ptr, serial_number, serial_number_len, &p, &len) != 1) { + error_print(); + return -1; + } + + if (cms_issuer_and_serial_number_from_der(&issuer, &serial_number, &serial_number_len, &cp, &len) != 1 + || asn1_length_is_zero(len) != 1) { + error_print(); + return -1; + } + cms_issuer_and_serial_number_print(stdout, &issuer, serial_number, serial_number_len, 0, 0); + + return 0; +} + +// 从这个测试可以看出,由于CMS类型非常复杂,因此最好能够将其打包称为一个struct,但是要区分指针类型和存储类型 +static int test_cms_recipient_info(void) +{ + FILE *key_fp = fopen("sign_key.pem", "r"); + FILE *cert_fp = fopen("sign_cert.pem", "r"); + X509_CERTIFICATE cert; + + X509_NAME issuer; + SM2_KEY sm2_key; + + const X509_NAME *issuer_ptr; + const uint8_t *serial_number; + size_t serial_number_len; + const SM2_KEY *pub_key; + + uint8_t key[128] = {1,2,3}; + size_t keylen = 16; + + + uint8_t buf[512]; + uint8_t *p = buf; + const uint8_t *cp = buf; + size_t len = 0; + + + if (x509_certificate_from_pem(&cert, cert_fp) != 1) { + error_print(); + return -1; + } + if (cms_public_key_from_certificate(&pub_key, &cert) != 1) { + error_print(); + return -1; + } + sm2_key_print(stdout, pub_key, 0, 0); + + if (cms_recipient_info_from_x509_certificate(&pub_key, &issuer_ptr, &serial_number, &serial_number_len, &cert) != 1) { + error_print(); + return -1; + } + + if (cms_recipient_info_encrypt_to_der(pub_key, issuer_ptr, serial_number, serial_number_len, key, keylen, &p, &len) != 1) { + error_print(); + return -1; + } + + int version; + int pke_algor; + const uint8_t *params; + size_t paramslen; + const uint8_t *enced_key; + size_t enced_key_len; + + /* + // 这个函数导致cp, len的长度发生变化 + if (cms_recipient_info_from_der(&version, &issuer, &serial_number, &serial_number_len, + &pke_algor, ¶ms, ¶mslen, + &enced_key, &enced_key_len, + &cp, &len) != 1) { + + error_print(); + return -1; + } + + cms_recipient_info_print(stdout, + version, &issuer, serial_number, serial_number_len, + pke_algor, params, paramslen, + enced_key, enced_key_len, + 0, 0); + */ + + if (sm2_private_key_from_pem(&sm2_key, key_fp) != 1) { + error_print(); + return -1; + } + sm2_key_print(stdout, &sm2_key, 0, 0); + + + if (cms_recipient_info_decrypt_from_der(&sm2_key, &issuer, &serial_number, &serial_number_len, key, &keylen, &cp, &len) != 1) { + error_print(); + return -1; + } + format_bytes(stdout, 0, 0, "decrypted_key : ", key, keylen); + + return 0; + +} + + +static int test_cms_enveloped_data(void) +{ + + FILE *key_fp = fopen("sign_key.pem", "r"); + FILE *cert_fp = fopen("sign_cert.pem", "r"); + X509_CERTIFICATE cert; + + X509_NAME issuer; + SM2_KEY sm2_key; + + const X509_NAME *issuer_ptr; + const uint8_t *serial_number; + size_t serial_number_len; + const SM2_KEY *pub_key; + + uint8_t key[128] = {1,2,3}; + size_t keylen = 16; + + + uint8_t buf[512]; + uint8_t *p = buf; + const uint8_t *cp = buf; + size_t len = 0; + + + if (x509_certificate_from_pem(&cert, cert_fp) != 1) { + error_print(); + return -1; + } + + uint8_t data[8]; + + if (cms_enveloped_data_encrypt_to_der(&cert, 1, + CMS_data, data, sizeof(data), + NULL, 0, NULL, 0, &p, &len) != 1) { + error_print(); + return -1; + } + error_print_msg("len = %zu\n", len); + + //cms_enveloped_data_print(stdout, cp, len, 0, 0); + //return 0; + + if (sm2_private_key_from_pem(&sm2_key, key_fp) != 1) { + error_print(); + return -1; + } + int content_type; + uint8_t content[512]; + size_t content_len; + const uint8_t *shared_info1, *shared_info2; + size_t shared_info1_len, shared_info2_len; + + if (cms_enveloped_data_decrypt_from_der( + &sm2_key, &cert, + &content_type, content, &content_len, + &shared_info1, &shared_info1_len, + &shared_info2, &shared_info2_len, + &cp, &len) != 1) { + error_print(); + return -1; + } + + + return 0; +} + + +static int test_cms_signer_info(void) +{ + FILE *key_fp = fopen("sign_key.pem", "r"); + FILE *cert_fp = fopen("sign_cert.pem", "r"); + X509_CERTIFICATE cert; + + X509_NAME issuer; + SM2_KEY sm2_key; + + const X509_NAME *issuer_ptr; + const uint8_t *serial_number; + size_t serial_number_len; + const SM2_KEY *pub_key; + + uint8_t key[128] = {1,2,3}; + size_t keylen = 16; + + uint8_t buf[512]; + uint8_t *p = buf; + const uint8_t *cp = buf; + size_t len = 0; + + if (x509_certificate_from_pem(&cert, cert_fp) != 1) { + error_print(); + return -1; + } + + if (cms_issuer_and_serial_number_from_certificate(&issuer_ptr, + &serial_number, &serial_number_len, &cert) != 1) { + error_print(); + return -1; + } + + uint8_t attrs[10]; + + if (cms_signer_info_to_der( + issuer_ptr, + serial_number, serial_number_len, + OID_sm3, + attrs, sizeof(attrs), + attrs, sizeof(attrs), + attrs, sizeof(attrs), + &p, &len) != 1) { + error_print(); + return -1; + } + + const uint8_t *authed_attrs, *unauthed_attrs, *sig; + size_t authed_attrs_len, unauthed_attrs_len, siglen; + int dgst_algor, sign_algor; + + if (cms_signer_info_from_der( + &issuer, + &serial_number, &serial_number_len, + &dgst_algor, + &authed_attrs, &authed_attrs_len, + &sign_algor, + &sig, &siglen, + &unauthed_attrs, &unauthed_attrs_len, + &cp, &len) != 1) { + error_print(); + return -1; + } + + + cms_signer_info_print(stdout, + 1, + &issuer, serial_number, serial_number_len, + dgst_algor, NULL, 0, + authed_attrs, authed_attrs_len, + sign_algor, NULL, 0, + sig, siglen, + unauthed_attrs, unauthed_attrs_len, + 0, 0); + + p = buf; + cp = buf; + len = 0; + + SM3_CTX sm3_ctx; + + // 这里根本没有测试验证过程 + +/* +270 int cms_signer_info_from_der(X509_NAME *issuer, +271 const uint8_t **serial_number, size_t *serial_number_len, +272 int *digest_algor, +273 const uint8_t **authed_attrs, size_t *authed_attrs_len, +274 int *sign_algor, +275 const uint8_t **enced_digest, size_t *enced_digest_len, +276 const uint8_t **unauthed_attrs, size_t *unauthed_attrs_len, +277 const uint8_t **in, size_t *inlen); +*/ + + + + + return 0; +} + +static int test_cms_signed_data(void) +{ + FILE *key_fp = fopen("sign_key.pem", "r"); + FILE *cert_fp = fopen("sign_cert.pem", "r"); + X509_CERTIFICATE cert; + + X509_NAME issuer; + SM2_KEY sm2_key; + + const X509_NAME *issuer_ptr; + const uint8_t *serial_number; + size_t serial_number_len; + const SM2_KEY *pub_key; + + uint8_t key[128] = {1,2,3}; + size_t keylen = 16; + + uint8_t buf[1512]; + uint8_t *p = buf; + const uint8_t *cp = buf; + size_t len = 0; + + uint8_t data[10] = {0}; + + + if (x509_certificate_from_pem(&cert, cert_fp) != 1) { + error_print(); + return -1; + } + if (sm2_private_key_from_pem(&sm2_key, key_fp) != 1) { + error_print(); + return -1; + } + + + if (cms_signed_data_sign_to_der(&sm2_key, &cert, 1, + CMS_data, data, sizeof(data), + NULL, 0, + &p, &len) != 1) { + error_print(); + return -1; + } + + cms_signed_data_print(stdout, buf, len, 0, 0); + + // 这个函数有问题,因为from_der返回的0和验证签名返回的0可能产生冲突 + // 还是应该直接提供一个函数,只做verify,不做from_der + + + int content_type; + const uint8_t *dgst_algors, *content, *certs, *crls, *signer_infos; + size_t dgst_algors_len, content_len, certs_len, crls_len, signer_infos_len; + + if (cms_signed_data_from_der( + &dgst_algors, &dgst_algors_len, + &content_type, &content, &content_len, + &certs, &certs_len, + &crls, &crls_len, + &signer_infos, &signer_infos_len, + &cp, &len) != 1) { + error_print(); + return -1; + } + + if (cms_signed_data_verify( + content_type, content, content_len, + certs, certs_len, + signer_infos, signer_infos_len) != 1) { + error_print(); + return -1; + } + + + return 0; + +} + + + static int test_cms_sign(void) { SM2_KEY sign_key; X509_CERTIFICATE sign_cert; - uint8_t data[20]; - uint8_t content_info[1024]; - size_t content_info_len = 0; + uint8_t in[20]; + uint8_t out[1024]; + size_t outlen = 0; FILE *key_fp = fopen("sign_key.pem", "r"); FILE *cert_fp = fopen("sign_cert.pem", "r"); @@ -90,95 +545,50 @@ static int test_cms_sign(void) error_print(); return -1; } - if (cms_sign(&sign_key, &sign_cert, 1, CMS_data, data, 20, NULL, NULL, 0, content_info, &content_info_len) != 1) { + + if (cms_sign(&sign_key, &sign_cert, 1, in, sizeof(in), out, &outlen) != 1) { error_print(); return -1; } - cms_content_info_print(stdout, content_info, content_info_len, 0, 0); - return 1; -} - - -static int test_cms_enced_content_info(void) -{ - uint8_t buf[512]; - uint8_t *p = buf; - const uint8_t *cp = buf; - size_t len = 0; - uint8_t iv[16]; - uint8_t enced_content[30]; - - if (cms_enced_content_info_to_der(OID_sm4_cbc, iv, sizeof(iv), - CMS_data, enced_content, sizeof(enced_content), - NULL, 0, - NULL, 0, - &p, &len) != 1) { - error_print(); - return -1; - } + cms_content_info_print(stdout, out, outlen, 0, 0); int content_type; - int enc_algor; - const uint8_t *enc_iv; - size_t enc_iv_len; - const uint8_t *penced_content; - size_t enced_content_len; - const uint8_t *shared_info1, *shared_info2; - size_t shared_info1_len, shared_info2_len; + const uint8_t *content, *certs, *crls, *signer_infos; + size_t content_len, certs_len, crls_len, signer_infos_len; - if (cms_enced_content_info_from_der(&content_type, - &enc_algor, &enc_iv, &enc_iv_len, - &penced_content, &enced_content_len, - &shared_info1, &shared_info1_len, - &shared_info2, &shared_info2_len, - &cp, &len) != 1) { + if (cms_verify(&content_type, &content, &content_len, + &certs, &certs_len, + &crls, &crls_len, + &signer_infos, &signer_infos_len, + out, outlen) != 1) { error_print(); return -1; } - return 1; } -static int test_cms_encrypt(void) -{ - uint8_t key[16]; - uint8_t msg[] = "Hello world!"; - uint8_t cbuf[512]; - uint8_t mbuf[512]; - size_t clen, mlen; - int content_type = 0; - const uint8_t *shared_info1 = NULL; - const uint8_t *shared_info2 = NULL; - size_t shared_info1_len, shared_info2_len; - - if (cms_encrypt(key, msg, sizeof(msg), cbuf, &clen) != 1) { - error_print(); - return -1; - } - - format_bytes(stderr, 0, 0, "EncryptedData\n", cbuf, clen); - if (cms_decrypt(key, cbuf, clen, &content_type, mbuf, &mlen, - &shared_info1, &shared_info1_len, - &shared_info2, &shared_info2_len) != 1) { - error_print(); - return -1; - } - return 1; -} + + + int main(void) { - // 很可能x509_algor.c中有错误! - test_cms_enced_content_info(); - //test_cms_encrypt(); //test_cms_data(); + //test_cms_enced_content_info(); + //test_cms_encrypt(); + //test_cms_key_agreement_info(); + //test_cms_issuer_and_serial_number(); + //test_cms_recipient_info(); + //test_cms_signer_info(); + //test_cms_signed_data(); + test_cms_enveloped_data(); //test_cms_sign(); return 0; } diff --git a/tests/destest.c b/tests/destest.c index 3dec6bbb..03fe345f 100644 --- a/tests/destest.c +++ b/tests/destest.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/tests/digesttest.c b/tests/digesttest.c index 4c5068b1..15050916 100644 --- a/tests/digesttest.c +++ b/tests/digesttest.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/tests/gcmtest.c b/tests/gcmtest.c index 54e74ac1..37f47dd5 100644 --- a/tests/gcmtest.c +++ b/tests/gcmtest.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/gf128test.c b/tests/gf128test.c index 1a93dc82..429e62ac 100644 --- a/tests/gf128test.c +++ b/tests/gf128test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/hash_drbgtest.c b/tests/hash_drbgtest.c index 3a303bd2..553edd1a 100644 --- a/tests/hash_drbgtest.c +++ b/tests/hash_drbgtest.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/hkdftest.c b/tests/hkdftest.c index 480d6e9d..fe750542 100644 --- a/tests/hkdftest.c +++ b/tests/hkdftest.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/hmactest.c b/tests/hmactest.c index a16ef276..363232a3 100644 --- a/tests/hmactest.c +++ b/tests/hmactest.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2018 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/md5test.c b/tests/md5test.c index d29ba0b8..65683831 100644 --- a/tests/md5test.c +++ b/tests/md5test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/tests/oidtest.c b/tests/oidtest.c index 7b6bdfdc..e4c32a0b 100644 --- a/tests/oidtest.c +++ b/tests/oidtest.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/pbkdf2test.c b/tests/pbkdf2test.c index 63700eaa..b709ab06 100644 --- a/tests/pbkdf2test.c +++ b/tests/pbkdf2test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/tests/pkcs8test.c b/tests/pkcs8test.c index 76affca9..57e1171c 100644 --- a/tests/pkcs8test.c +++ b/tests/pkcs8test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * -sm2_enced_private_key_info_from_der * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/rc4test.c b/tests/rc4test.c index a3077090..55de082a 100644 --- a/tests/rc4test.c +++ b/tests/rc4test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/tests/sha1test.c b/tests/sha1test.c index 71c26981..e1e04193 100644 --- a/tests/sha1test.c +++ b/tests/sha1test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/sha224test.c b/tests/sha224test.c index 926c0502..bb37619d 100644 --- a/tests/sha224test.c +++ b/tests/sha224test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/sha256test.c b/tests/sha256test.c index a60aab61..a4922fe8 100644 --- a/tests/sha256test.c +++ b/tests/sha256test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/tests/sha384test.c b/tests/sha384test.c index a7fe6131..e9aace89 100644 --- a/tests/sha384test.c +++ b/tests/sha384test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/tests/sha512test.c b/tests/sha512test.c index 8275452e..added4ee 100644 --- a/tests/sha512test.c +++ b/tests/sha512test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/tests/sm2asn1test.c b/tests/sm2asn1test.c index c041940c..c1e29d4f 100644 --- a/tests/sm2asn1test.c +++ b/tests/sm2asn1test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/sm2test.c b/tests/sm2test.c index 90389d99..003a3640 100644 --- a/tests/sm2test.c +++ b/tests/sm2test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/sm3test.c b/tests/sm3test.c index e5282ac4..8e8f6670 100644 --- a/tests/sm3test.c +++ b/tests/sm3test.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/sm4cbctest.c b/tests/sm4cbctest.c index 96d4e856..5d9a4743 100644 --- a/tests/sm4cbctest.c +++ b/tests/sm4cbctest.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/sm4test.c b/tests/sm4test.c index 16567ca8..fe2e3d7c 100644 --- a/tests/sm4test.c +++ b/tests/sm4test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/tlstest.c b/tests/tlstest.c index 8bf40ce2..9f72516e 100644 --- a/tests/tlstest.c +++ b/tests/tlstest.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/x509_algortest.c b/tests/x509_algortest.c new file mode 100644 index 00000000..edcfde93 --- /dev/null +++ b/tests/x509_algortest.c @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the GmSSL Project. + * (http://gmssl.org/)" + * + * 4. The name "GmSSL Project" must not be used to endorse or promote + * products derived from this software without prior written + * permission. For written permission, please contact + * guanzhi1980@gmail.com. + * + * 5. Products derived from this software may not be called "GmSSL" + * nor may "GmSSL" appear in their names without prior written + * permission of the GmSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the GmSSL Project + * (http://gmssl.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include + + +static int test_x509_digest_algor(void) +{ + char *names[] = {"sm3", "md5", "sha1", "sha224", "sha256", "sha384", "sha512" }; + uint8_t buf[256]; + uint8_t *p = buf; + const uint8_t *cp = buf; + size_t len = 0; + int algor; + uint32_t nodes[32]; + size_t nodes_count; + int i, j; + + printf("\n%s\n", __FUNCTION__); + + for (i = 0; i < sizeof(names)/sizeof(names[0]); i++) { + algor = x509_digest_algor_from_name(names[i]); + if (x509_digest_algor_to_der(algor, &p, &len) != 1) { + error_print(); + return -1; + } + } + for (i = 0; i < sizeof(names)/sizeof(names[0]); i++) { + if (x509_digest_algor_from_der(&algor, nodes, &nodes_count, &cp, &len) != 1) { + error_print(); + return -1; + } + printf(" %s : ", x509_digest_algor_name(algor)); + for (j = 0; j < nodes_count; j++) { + printf("%d ", nodes[j]); + } + printf("\n"); + } + return 0; +} + +static int test_x509_encryption_algor(void) +{ + char *names[] = { "sm4-cbc", "aes128-cbc", "aes192-cbc", "aes256-cbc" }; + uint8_t iv[16] = {0}; + uint8_t buf[256]; + uint8_t *p = buf; + const uint8_t *cp = buf; + size_t len = 0; + int algor; + uint32_t nodes[32]; + size_t nodes_count; + const uint8_t *params; + size_t paramslen; + int i, j; + + printf("\n%s\n", __FUNCTION__); + + for (i = 0; i < sizeof(names)/sizeof(names[0]); i++) { + algor = x509_encryption_algor_from_name(names[i]); + if (x509_encryption_algor_to_der(algor, iv, sizeof(iv), &p, &len) != 1) { + error_print(); + return -1; + } + } + for (i = 0; i < sizeof(names)/sizeof(names[0]); i++) { + if (x509_encryption_algor_from_der(&algor, nodes, &nodes_count, ¶ms, ¶mslen, &cp, &len) != 1) { + error_print(); + return -1; + } + printf(" %s : ", x509_encryption_algor_name(algor)); + for (j = 0; j < nodes_count; j++) { + printf("%d ", nodes[j]); + } + printf("\n"); + } + return 0; +} + +static int test_x509_signature_algor(void) +{ + char *names[] = { + "sm2sign-with-sm3", + "rsasign-with-sm3", + "ecdsa-with-sha1", + "ecdsa-with-sha224", + "ecdsa-with-sha256", + "ecdsa-with-sha384", + "ecdsa-with-sha512", + "sha1WithRSAEncryption", + "sha224WithRSAEncryption", + "sha256WithRSAEncryption", + "sha384WithRSAEncryption", + "sha512WithRSAEncryption", + }; + uint8_t buf[256]; + uint8_t *p = buf; + const uint8_t *cp = buf; + size_t len = 0; + int algor; + uint32_t nodes[32]; + size_t nodes_count; + int i, j; + + printf("\n%s\n", __FUNCTION__); + + for (i = 0; i < sizeof(names)/sizeof(names[0]); i++) { + algor = x509_signature_algor_from_name(names[i]); + if (x509_signature_algor_to_der(algor, &p, &len) != 1) { + error_print(); + return -1; + } + } + for (i = 0; i < sizeof(names)/sizeof(names[0]); i++) { + if (x509_signature_algor_from_der(&algor, nodes, &nodes_count, &cp, &len) != 1) { + error_print(); + return -1; + } + printf(" %s : ", x509_signature_algor_name(algor)); + for (j = 0; j < nodes_count; j++) { + printf("%d ", nodes[j]); + } + printf("\n"); + } + return 0; +} + +static int test_x509_public_key_encryption_algor(void) +{ + char *names[] = {"sm2encrypt", "rsaesOAEP", "rsaEncryption" }; + uint8_t buf[256]; + uint8_t *p = buf; + const uint8_t *cp = buf; + size_t len = 0; + int algor; + uint32_t nodes[32]; + size_t nodes_count; + const uint8_t *params; + size_t paramslen; + int i, j; + + printf("\n%s\n", __FUNCTION__); + + for (i = 0; i < sizeof(names)/sizeof(names[0]); i++) { + algor = x509_public_key_encryption_algor_from_name(names[i]); + if (x509_public_key_encryption_algor_to_der(algor, &p, &len) != 1) { + error_print(); + return -1; + } + } + for (i = 0; i < sizeof(names)/sizeof(names[0]); i++) { + if (x509_public_key_encryption_algor_from_der(&algor, nodes, &nodes_count, ¶ms, ¶mslen, &cp, &len) != 1) { + error_print(); + return -1; + } + printf(" %s : ", x509_public_key_encryption_algor_name(algor)); + for (j = 0; j < nodes_count; j++) { + printf("%d ", nodes[j]); + } + printf("\n"); + } + return 0; +} + + + + + + + + + + + + + + + + + + + +int main(void) +{ + int err = 0; + err += test_x509_digest_algor(); + err += test_x509_encryption_algor(); + err += test_x509_signature_algor(); + err += test_x509_public_key_encryption_algor(); + return err; +} diff --git a/tests/x509test.c b/tests/x509test.c index 6b30968a..f45370c0 100644 --- a/tests/x509test.c +++ b/tests/x509test.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tests/zuctest.c b/tests/zuctest.c index 4b05da74..ccf245b4 100644 --- a/tests/zuctest.c +++ b/tests/zuctest.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2018 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tools/README.md b/tools/README.md index 105c62bd..d887ceb7 100644 --- a/tools/README.md +++ b/tools/README.md @@ -1,3 +1,16 @@ -# Command Line Tools +# 命令行工具 +命令行工具: + +* `sm3` 计算SM3杂凑值,支持带公钥和ID的Z值计算 +* `sm3hmac` 计算SM3-HMAC值 +* `sm2keygen` 生成SM2密钥对,以PKCS #8口令加密的PEM格式存储 +* `sm2sign`,`sm2verify` SM2签名和验证,生成DER二进制编码的SM2签名值 +* `sm2encrypt`,`sm2decrypt` SM2加解密,注意只支持较短的消息加密 +* `reqgen` 生成PKCS #10证书签名请求PEM文件 +* `reqparse` 解析打印REQ文件 +* `reqsign` CA用私钥对REQ文件签名,生成证书 +* `certgen`生成自签名证书 +* `certparse` 解析打印证书 +* `certverify` 验证证书链 diff --git a/tools/certgen.c b/tools/certgen.c index 51a8d47e..87b28db1 100644 --- a/tools/certgen.c +++ b/tools/certgen.c @@ -1,55 +1,22 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include #include #include -#include #include #include #include @@ -57,6 +24,12 @@ #include +#ifndef WIN32 +#include +#include +#endif + + /* from RFC 2253 @@ -85,7 +58,8 @@ void print_usage(const char *prog) printf(" -L locality name\n"); printf(" -ST state of province name\n"); printf(" -days validity days\n"); - printf(" -keyfile private key file\n"); + printf(" -key private key file\n"); + printf(" -pass pass password\n"); } int main(int argc, char **argv) @@ -99,12 +73,14 @@ int main(int argc, char **argv) char *common_name = NULL; char *keyfile = NULL; int days = 0; + char *outfile = NULL; FILE *keyfp = NULL; + FILE *outfp = stdout; X509_CERTIFICATE cert; - char *pass; + char *pass = NULL; uint8_t serial[12]; X509_NAME name; @@ -128,15 +104,10 @@ int main(int argc, char **argv) OID_kp_OCSPSigning, }; - - if (argc < 2) { - print_usage(prog); - return 0; - } - argc--; argv++; - while (argc >= 1) { + + while (argc > 0) { if (!strcmp(*argv, "-help")) { print_usage(prog); return 0; @@ -161,7 +132,7 @@ int main(int argc, char **argv) if (--argc < 1) goto bad; state = *(++argv); - } else if (!strcmp(*argv, "-keyfile")) { + } else if (!strcmp(*argv, "-key")) { if (--argc < 1) goto bad; keyfile = *(++argv); @@ -169,25 +140,50 @@ int main(int argc, char **argv) if (--argc < 1) goto bad; days = atoi(*(++argv)); + } else if (!strcmp(*argv, "-pass")) { + if (--argc < 1) goto bad; + pass = *(++argv); + + } else if (!strcmp(*argv, "-out")) { + if (--argc < 1) goto bad; + outfile = *(++argv); + + } else { + fprintf(stderr, "%s: illegal option '%s'\n", prog, *argv); print_usage(prog); return 0; - break; } argc--; argv++; } - if (days <= 0 && !keyfile) { + if (days <= 0 || !keyfile) { + error_print(); goto bad; } if (!(keyfp = fopen(keyfile, "r"))) { + error_print(); goto bad; } - pass = getpass("Password : "); + if (!pass) { +#ifndef WIN32 + pass = getpass("Encryption Password : "); +#else + fprintf(stderr, "%s: '-pass' option required\n", prog); +#endif + } + + if (outfile) { + if (!(outfp = fopen(outfile, "wb"))) { + error_print(); + return -1; + } + } + if (sm2_enced_private_key_info_from_pem(&sm2_key, pass, keyfp) != 1) { error_print(); goto end; @@ -266,7 +262,7 @@ int main(int argc, char **argv) x509_certificate_sign_sm2(&cert, &sm2_key); - x509_certificate_to_pem(&cert, stdout); + x509_certificate_to_pem(&cert, outfp); ret = 0; goto end; diff --git a/tools/certparse.c b/tools/certparse.c new file mode 100644 index 00000000..a8b4e222 --- /dev/null +++ b/tools/certparse.c @@ -0,0 +1,44 @@ +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + + +int main(void) +{ + X509_CERTIFICATE cert; + for (;;) { + int ret = x509_certificate_from_pem(&cert, stdin); + if (ret < 0) { + error_print(); + return -1; + } + if (ret == 0) { + goto end; + } + fprintf(stdout, "Certificate\n"); + x509_certificate_print(stdout, &cert, 0, 0); + x509_certificate_to_pem(&cert, stdout); + fprintf(stdout, "\n"); + } +end: + return 0; +} diff --git a/tools/certverify.c b/tools/certverify.c index 55ad4e74..31dac3ea 100644 --- a/tools/certverify.c +++ b/tools/certverify.c @@ -1,61 +1,32 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include #include #include -//#include #include #include #include #include #include +// 验证证书链是一个重量级的功能,应准备相应的文档,列举所有验证项目 +// 比如最基本的是证书中的签名、有效期、各个扩展等 +// 外部相关的:证书链、CRL等 + static int verify_cert(const X509_CERTIFICATE *cert, const X509_CERTIFICATE *cacert) { diff --git a/tools/certview.c b/tools/certview.c deleted file mode 100644 index 1e0dba56..00000000 --- a/tools/certview.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include - - -int main(void) -{ - X509_CERTIFICATE cert; - for (;;) { - int ret = x509_certificate_from_pem(&cert, stdin); - if (ret < 0) { - error_print(); - return -1; - } - if (ret == 0) { - goto end; - } - fprintf(stdout, "Certificate\n"); - x509_certificate_print(stdout, &cert, 0, 0); - x509_certificate_to_pem(&cert, stdout); - fprintf(stdout, "\n"); - } -end: - return 0; -} diff --git a/tools/digest.c b/tools/digest.c index c2127e83..427ec283 100644 --- a/tools/digest.c +++ b/tools/digest.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tools/hmac.c b/tools/hmac.c index f4e51a6c..9c1d1c76 100644 --- a/tools/hmac.c +++ b/tools/hmac.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tools/oid.c b/tools/oid.c deleted file mode 100644 index a8bfd0f4..00000000 --- a/tools/oid.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include - - -// 对OID的几种类型进行转换 -// name, oid int值,DER编码 -oid 112 -name -der -// 这里我们要做类型转换 - -/* - -oid -name secp256k1 -secp256k1 : 1.2.3.4 : 030201220308 : hello world - - -*/ - -void print_usage(FILE *out, const char *prog) -{ - fprintf(out, "Usage: %s command [options] ...\n", prog); - fprintf(out, "\n"); - fprintf(out, "Commands:\n"); - fprintf(out, " -help print the usage message\n"); - fprintf(out, " -name oid name string\n"); - fprintf(out, " -oid oid value\n"); - fprintf(out, " -der oid der encoding in hex\n"); -} - - -int oid_vec_to_der(const unsigned int *oid, size_t oidlen, uint8_t *out, size_t *outlen) -{ - if (oidlen < 2) { - return -1; - } - - *out++ = oid[0] * 40 + oid[1]; - oidlen -= 2; - *outlen++; - - while (oidlen > 0) { - id (*oid < 128) { - *out++ = (uint8_t)(*oid); - } else { - *out++ = 0x80 & ((uint8_t)(*oid >> 8) << 1); - *out++ = 0x80 | (uint8_t)(*oid); - } - oid++; - oidlen--; - } - -} - -int main(int argc, char **argv) -{ - int ret = -1; - char *prog = argv[0]; - int help = 0; - - argc--; - argv++; - while (argc >= 0) { - } -} diff --git a/tools/pkcs8gen.c b/tools/pkcs8gen.c index a1727aed..c16cbd01 100644 --- a/tools/pkcs8gen.c +++ b/tools/pkcs8gen.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tools/pkcs8view.c b/tools/pkcs8view.c deleted file mode 100644 index 50e45bfe..00000000 --- a/tools/pkcs8view.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int main(void) -{ - SM2_KEY key; - const char *pass = NULL; - - pass = getpass("Password : "); - if (sm2_enced_private_key_info_from_pem(&key, pass, stdin) != 1) { - error_print(); - return -1; - } - sm2_key_print(stdout, &key, 0, 0); - sm2_public_key_info_to_pem(&key, stdout); - return 0; -} diff --git a/tools/reqgen.c b/tools/reqgen.c index ce3f424d..3a305312 100644 --- a/tools/reqgen.c +++ b/tools/reqgen.c @@ -1,55 +1,22 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include #include #include -#include #include #include #include @@ -57,9 +24,16 @@ #include +#ifndef WIN32 +#include +#include +#endif + + + void print_usage(const char *prog) { - printf("Usage: %s command [options] ...\n", prog); + printf("usage: %s command [options] ...\n", prog); printf("\n"); printf("Options:\n"); printf(" -C country name\n"); @@ -71,6 +45,8 @@ void print_usage(const char *prog) printf("\n"); printf(" -days validity days\n"); printf(" -keyfile private key file\n"); + printf(" -pass password password\n"); + printf(" -out file output req file\n"); } int main(int argc, char **argv) @@ -83,14 +59,15 @@ int main(int argc, char **argv) char *org_unit = NULL; char *common_name = NULL; char *keyfile = NULL; + char *pass = NULL; + char *outfile = NULL; int days = 0; FILE *keyfp = NULL; + FILE *outfp = stdout; X509_CERT_REQUEST req; - char *pass; - X509_NAME name; SM2_KEY sm2_key; // 这个应该是从文件中读取的! @@ -102,6 +79,7 @@ int main(int argc, char **argv) argc--; argv++; + while (argc >= 1) { if (!strcmp(*argv, "-help")) { print_usage(prog); @@ -131,10 +109,18 @@ int main(int argc, char **argv) if (--argc < 1) goto bad; keyfile = *(++argv); + } else if (!strcmp(*argv, "-pass")) { + if (--argc < 1) goto bad; + pass = *(++argv); + } else if (!strcmp(*argv, "-days")) { if (--argc < 1) goto bad; days = atoi(*(++argv)); + } else if (!strcmp(*argv, "-out")) { + if (--argc < 1) goto bad; + outfile = *(++argv); + } else { print_usage(prog); return 0; @@ -153,7 +139,22 @@ int main(int argc, char **argv) goto bad; } - pass = getpass("Password : "); + + if (outfile) { + if (!(outfp = fopen(outfile, "w"))) { + error_print(); + return -1; + } + } + + if (!pass) { +#ifndef WIN32 + pass = getpass("Encryption Password : "); +#else + fprintf(stderr, "%s: '-pass' option required\n", prog); +#endif + } + if (sm2_enced_private_key_info_from_pem(&sm2_key, pass, keyfp) != 1) { error_print(); goto end; @@ -204,7 +205,8 @@ int main(int argc, char **argv) x509_cert_request_set(&req, &name, &sm2_key); x509_cert_request_sign(&req, &sm2_key); - x509_cert_request_to_pem(&req, stdout); + x509_cert_request_to_pem(&req, outfp); + ret = 0; goto end; diff --git a/tools/reqparse.c b/tools/reqparse.c new file mode 100644 index 00000000..f50f693d --- /dev/null +++ b/tools/reqparse.c @@ -0,0 +1,81 @@ +<<<<<<< HEAD:tools/reqparse.c +/* + * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. +======= +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. +>>>>>>> 5fc13a8aefa3fb395f32927e35dda4210a3c1a23:tools/pkcs8view.c + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + + +int main(int argc, char **argv) +{ + char *prog = argv[0]; + char *infile = NULL; + X509_CERT_REQUEST req; + FILE *infp = stdin; + + argc--; + argv++; + + while (argc > 0) { + if (!strcmp(*argv, "-help")) { +help: + fprintf(stderr, "usage: %s [-in file]\n", prog); + return -1; + + } else if(!strcmp(*argv, "-in")) { + if (--argc < 1) goto bad; + infile = *(++argv); + + } else { + fprintf(stderr, "%s: illegal option '%s'\n", prog, *argv); + goto help; + } + + argc--; + argv++; + } + + if (infile) { + if (!(infp = fopen(infile, "r"))) { + error_print(); + return -1; + } + } + + int ret = x509_cert_request_from_pem(&req, infp); + if (ret < 0) { + error_print(); + return -1; + } + if (ret == 0) { + error_print(); + return -1; + } + x509_cert_request_print(stdout, &req, 0, 0); + return 0; + +bad: + fprintf(stderr, "%s: '%s' option value required\n", prog, *argv); + return -1; +} diff --git a/tools/reqsign.c b/tools/reqsign.c index 9b43793e..ff0dbb9d 100644 --- a/tools/reqsign.c +++ b/tools/reqsign.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tools/sm2decrypt.c b/tools/sm2decrypt.c index b582aeec..fe90678e 100644 --- a/tools/sm2decrypt.c +++ b/tools/sm2decrypt.c @@ -1,55 +1,22 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include #include #include -#include #include #include #include @@ -57,37 +24,58 @@ #include +#ifndef WIN32 +#include +#include +#endif + + int main(int argc, char **argv) { char *prog = argv[0]; - const char *keyfile = NULL; + char *keyfile = NULL; + char *pass = NULL; + char *infile = NULL; + char *outfile = NULL; FILE *keyfp = NULL; - const char *pass = NULL; + FILE *infp = stdin; + FILE *outfp = stdout; SM2_KEY key; - char hexbuf[SM2_MAX_CIPHERTEXT_SIZE * 2]; - uint8_t inbuf[SM2_MAX_CIPHERTEXT_SIZE * 2]; + uint8_t inbuf[SM2_MAX_CIPHERTEXT_SIZE]; uint8_t outbuf[SM2_MAX_CIPHERTEXT_SIZE]; - size_t hexlen, inlen, outlen; - - if (argc < 2) { -bad: - fprintf(stderr, "%s : error options\n", prog); -help: - fprintf(stderr, "usage: %s -key key.pem [-id str] < file\n", prog); - return 1; - } + size_t inlen, outlen; argc--; argv++; - while (argc > 1) { + + while (argc > 0) { + if (!strcmp(*argv, "-help")) { +help: + fprintf(stderr, "usage: %s -key pem [-pass password] [-in file] [-out file]\n", prog); goto help; + } else if (!strcmp(*argv, "-key")) { if (--argc < 1) goto bad; keyfile = *(++argv); + + } else if (!strcmp(*argv, "-pass")) { + if (--argc < 1) goto bad; + pass = *(++argv); + + } else if (!strcmp(*argv, "-in")) { + if (--argc < 1) goto bad; + infile = *(++argv); + + } else if (!strcmp(*argv, "-out")) { + if (--argc < 1) goto bad; + outfile = *(++argv); + } else { + fprintf(stderr, "%s: illegal option '%s'\n", prog, *argv); goto help; } + argc--; argv++; } @@ -100,24 +88,59 @@ help: error_print(); return -1; } - pass = getpass("Encryption Password : "); + + if (!pass) { +#ifndef WIN32 + pass = getpass("Encryption Password : "); +#else + fprintf(stderr, "%s: '-pass' option required\n", prog); +#endif + } + + if (infile) { + if (!(infp = fopen(infile, "rb"))) { + error_print(); + return -1; + } + } + + if (outfile) { + if (!(outfp = fopen(outfile, "wb"))) { + error_print(); + return -1; + } + } + if (sm2_enced_private_key_info_from_pem(&key, pass, keyfp) != 1) { error_puts("private key decryption failure"); return -1; } - if ((hexlen = fread(hexbuf, 1, sizeof(hexbuf), stdin)) <= 0) { + + if ((inlen = fread(inbuf, 1, sizeof(inbuf), infp)) <= 0) { error_print(); return -1; } - if (hex2bin(hexbuf, hexlen, inbuf) != 1) { + if (sm2_decrypt(&key, inbuf, inlen, outbuf, &outlen) != 1) { error_print(); return -1; } - if (sm2_decrypt(&key, inbuf, hexlen/2, outbuf, &outlen) != 1) { + + error_print_msg("outlen = %zu\n", outlen); + + if (outlen != fwrite(outbuf, 1, outlen, outfp)) { error_print(); return -1; } - fwrite(outbuf, 1, outlen, stdout); + + memset(&key, 0, sizeof(SM2_KEY)); + + // FIXME: 清空所有缓冲区 + if (infile) fclose(infp); + if (outfile) fclose(outfp); return 0; +bad: + fprintf(stderr, "%s: '%s' option value required\n", prog, *argv); + return -1; + } diff --git a/tools/sm2encrypt.c b/tools/sm2encrypt.c index afa33df4..56c932c3 100644 --- a/tools/sm2encrypt.c +++ b/tools/sm2encrypt.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include @@ -62,39 +30,45 @@ int main(int argc, char **argv) { int ret; char *prog = argv[0]; - const char *keyfile = NULL; - const char *certfile = NULL; - FILE *keyfp = NULL; + char *pubkeyfile = NULL; + char *certfile = NULL; + char *infile = NULL; + char *outfile = NULL; + FILE *pubkeyfp = NULL; FILE *certfp = NULL; + FILE *infp = stdin; + FILE *outfp = stdout; X509_CERTIFICATE cert; SM2_KEY key; uint8_t inbuf[SM2_MAX_PLAINTEXT_SIZE]; - ssize_t inlen; uint8_t outbuf[SM2_MAX_CIPHERTEXT_SIZE]; - size_t outlen = sizeof(outbuf); - - if (argc < 2) { -bad: - fprintf(stderr, "%s : error options\n", prog); -help: - fprintf(stderr, "usage:\n"); - fprintf(stderr, " %s -pubkey key.pem < file\n", prog); - fprintf(stderr, " %s -cert cert.pem < file\n", prog); - fprintf(stderr, "\n"); - return 1; - } + size_t inlen, outlen = sizeof(outbuf); argc--; argv++; + while (argc > 1) { if (!strcmp(*argv, "-help")) { - goto help; +help: + fprintf(stderr, "usage: %s {-pubkey pem | -cert pem} [-in file] [-out file]\n", prog); + return -1; + } else if (!strcmp(*argv, "-pubkey")) { if (--argc < 1) goto bad; - keyfile = *(++argv); + pubkeyfile = *(++argv); + } else if (!strcmp(*argv, "-cert")) { if (--argc < 1) goto bad; certfile = *(++argv); + + } else if (!strcmp(*argv, "-in")) { + if (--argc < 1) goto bad; + infile = *(++argv); + + } else if (!strcmp(*argv, "-out")) { + if (--argc < 1) goto bad; + outfile = *(++argv); + } else { goto help; } @@ -102,20 +76,16 @@ help: argv++; } - if ((!keyfile && !certfile) || (keyfile && certfile)) { - error_print(); - return -1; - } - if (keyfile) { - if (!(keyfp = fopen(keyfile, "r"))) { + if (pubkeyfile) { + if (!(pubkeyfp = fopen(pubkeyfile, "r"))) { error_print(); return -1; } - if (sm2_public_key_info_from_pem(&key, keyfp) != 1) { + if (sm2_public_key_info_from_pem(&key, pubkeyfp) != 1) { error_print(); return -1; } - } else { + } else if (certfile) { if (!(certfp = fopen(certfile, "r"))) { error_print(); return -1; @@ -128,9 +98,26 @@ help: error_print(); return -1; } + } else { + fprintf(stderr, "%s: '-pubkey' or '-cert' required\n", prog); + goto help; } - if ((inlen = read(STDIN_FILENO, inbuf, sizeof(inbuf))) <= 0) { + if (infile) { + if (!(infp = fopen(infile, "rb"))) { + error_print(); + return -1; + } + } + if (outfile) { + if (!(outfp = fopen(outfile, "wb"))) { + error_print(); + return -1; + } + } + + + if ((inlen = fread(inbuf, 1, sizeof(inbuf), infp)) <= 0) { error_print(); return -1; } @@ -138,6 +125,14 @@ help: error_print(); return -1; } - format_bytes(stdout, 0, 0, "", outbuf, outlen); - return 1; + + if (outlen != fwrite(outbuf, 1, outlen, outfp)) { + error_print(); + return -1; + } + return 0; + +bad: + fprintf(stderr, "%s: '%s' option value required\n", prog, *argv); + return -1; } diff --git a/tools/sm2gen.c b/tools/sm2gen.c deleted file mode 100644 index ee5513a7..00000000 --- a/tools/sm2gen.c +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include - -int main(void) -{ - SM2_KEY key; - - if (sm2_keygen(&key) != 1) { - error_print(); - return -1; - } - if (sm2_private_key_to_pem(&key, stdout) != 1) { - error_print(); - return -1; - } - return 0; -} diff --git a/tools/sm2keygen.c b/tools/sm2keygen.c new file mode 100644 index 00000000..62dbed90 --- /dev/null +++ b/tools/sm2keygen.c @@ -0,0 +1,122 @@ +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef WIN32 +#include +#include +#endif + +int main(int argc, char **argv) +{ + char *prog = argv[0]; + char *pass = NULL; + char passbuf[64] = {0}; + char *outfile = NULL; + char *puboutfile = NULL; + FILE *outfp = stdout; + FILE *puboutfp = stdout; + SM2_KEY key; + + argc--; + argv++; + + while (argc > 0) { + if (!strcmp(*argv, "-help")) { +help: + fprintf(stderr, "usage: %s [-pass passphrase] [-out pem] [-pubout pem]\n", prog); + return -1; + + } else if (!strcmp(*argv, "-pass")) { + if (--argc < 1) goto bad; + pass = *(++argv); + + } else if (!strcmp(*argv, "-out")) { + if (--argc < 1) goto bad; + outfile = *(++argv); + + } else if (!strcmp(*argv, "-pubout")) { + if (--argc < 1) goto bad; + puboutfile = *(++argv); + + } else { + fprintf(stderr, "%s: illegal option '%s'\n", prog, *argv); + goto help; + } + + argc--; + argv++; + } + + + if (!pass) { +#ifndef WIN32 + pass = getpass("Encryption Password : "); + strncpy(passbuf, pass, sizeof(passbuf)); + pass = getpass("Encryption Password (Again) : "); + if (strcmp(passbuf, pass) != 0) { + fprintf(stderr, "error: passwords not match\n"); + return -1; + } +#else + fprintf(stderr, "%s: '-pass' option required\n", prog); + goto help; +#endif + } + + if (outfile) { + if (!(outfp = fopen(outfile, "w"))) { + error_print(); + return -1; + } + } + if (puboutfile) { + if (!(puboutfp = fopen(puboutfile, "w"))) { + error_print(); + return -1; + } + } + + if (sm2_keygen(&key) != 1) { + error_print(); + return -1; + } + + if (sm2_enced_private_key_info_to_pem(&key, pass, outfp) != 1) { + memset(&key, 0, sizeof(SM2_KEY)); + error_print(); + return -1; + } + if (sm2_public_key_info_to_pem(&key, puboutfp) != 1) { + memset(&key, 0, sizeof(SM2_KEY)); + error_print(); + return -1; + } + + memset(&key, 0, sizeof(SM2_KEY)); + return 0; + +bad: + fprintf(stderr, "%s: '%s' option value required\n", prog, *argv); + return -1; +} diff --git a/tools/sm2pub.c b/tools/sm2pub.c deleted file mode 100644 index e4166758..00000000 --- a/tools/sm2pub.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -// 输入一个PKCS #8 加密格式的私钥,输出一个EC公钥 - - -int main(void) -{ - SM2_KEY key; - char *pass = NULL; - char passbuf[64] = {0}; - - pass = getpass("Encryption Password : "); - strncpy(passbuf, pass, sizeof(passbuf)); - pass = getpass("Encryption Password (Again) : "); - if (strcmp(passbuf, pass) != 0) { - fprintf(stderr, "error: passwords not match\n"); - return -1; - } - - sm2_keygen(&key); - sm2_enced_private_key_info_to_pem(&key, pass, stdout); - - return 0; -} diff --git a/tools/sm2sign.c b/tools/sm2sign.c index 73edce84..c3a19f48 100644 --- a/tools/sm2sign.c +++ b/tools/sm2sign.c @@ -1,49 +1,22 @@ -/* +<<<<<<< HEAD +/* * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +======= +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. +>>>>>>> 5fc13a8aefa3fb395f32927e35dda4210a3c1a23 * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include @@ -55,19 +28,26 @@ #include #include +#ifndef WIN32 +#include +#include +#endif + + // echo data | sm2sign -id "Alice" -keyfile sm2.pem // echo data | sm2verify -id "Alice" -keyfile sm2pub.pem -certfile a -cacertfile b - - - int main(int argc, char **argv) { char *prog = argv[0]; - const char *id = SM2_DEFAULT_ID; - const char *keyfile = NULL; + char *keyfile = NULL; + char *pass = NULL; + char *id = SM2_DEFAULT_ID; + char *infile = NULL; + char *outfile = NULL; FILE *keyfp = NULL; - const char *pass = NULL; + FILE *infp = stdin; + FILE *outfp = stdout; SM2_KEY key; SM2_SIGN_CTX sign_ctx; uint8_t buf[4096]; @@ -75,52 +55,95 @@ int main(int argc, char **argv) uint8_t sig[SM2_MAX_SIGNATURE_SIZE]; size_t siglen; - if (argc < 2) { -bad: - fprintf(stderr, "%s : error options\n", prog); -help: - fprintf(stderr, "usage: %s -key key.pem [-id str] < file\n", prog); - return 1; - } - argc--; argv++; - while (argc > 1) { + + while (argc > 0) { if (!strcmp(*argv, "-help")) { - goto help; - } else if (!strcmp(*argv, "-id")) { - if (--argc < 1) goto bad; - id = *(++argv); +help: + fprintf(stderr, "usage: %s -key pem [-pass password] [-id str] [-in file] [-out file]\n", prog); + return -1; + } else if (!strcmp(*argv, "-key")) { if (--argc < 1) goto bad; keyfile = *(++argv); + + } else if (!strcmp(*argv, "-pass")) { + if (--argc < 1) goto bad; + pass = *(++argv); + + } else if (!strcmp(*argv, "-id")) { + if (--argc < 1) goto bad; + id = *(++argv); + + } else if (!strcmp(*argv, "-in")) { + if (--argc < 1) goto bad; + infile = *(++argv); + + } else if (!strcmp(*argv, "-out")) { + if (--argc < 1) goto bad; + outfile = *(++argv); + } else { + fprintf(stderr, "%s: illegal option '%s'\n", prog, *argv); goto help; } + argc--; argv++; } if (!keyfile) { error_print(); - return -1; + goto help; } if (!(keyfp = fopen(keyfile, "r"))) { error_print(); return -1; } - pass = getpass("Encryption Password : "); + + if (!pass) { +#ifndef WIN32 + pass = getpass("Encryption Password : "); +#else + fprintf(stderr, "%s: '-pass' option required\n", prog); +#endif + } + + if (infile) { + if (!(infp = fopen(infile, "rb"))) { + error_print(); + return -1; + } + } + + if (outfile) { + if (!(outfp = fopen(outfile, "wb"))) { + error_print(); + return -1; + } + } + if (sm2_enced_private_key_info_from_pem(&key, pass, keyfp) != 1) { error_puts("private key decryption failure"); return -1; } sm2_sign_init(&sign_ctx, &key, id); - while ((len = read(STDIN_FILENO, buf, sizeof(buf))) > 0) { + + while ((len = fread(buf, 1, sizeof(buf), infp)) > 0) { sm2_sign_update(&sign_ctx, buf, len); } sm2_sign_finish(&sign_ctx, sig, &siglen); - format_bytes(stdout, 0, 0, "", sig, siglen); + + fwrite(sig, 1, siglen, outfp); + + memset(&key, 0, sizeof(SM2_KEY)); + + return 0; +bad: + fprintf(stderr, "%s: '%s' option value required\n", prog, *argv); + return -1; } diff --git a/tools/sm2verify.c b/tools/sm2verify.c index e3fe41f4..08335d00 100644 --- a/tools/sm2verify.c +++ b/tools/sm2verify.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include @@ -58,83 +26,78 @@ #include +// sm2verify [-in file] {-pubkey pem | -cert pem} [-id str] -sig file + int main(int argc, char **argv) { int ret; char *prog = argv[0]; - const char *sig_hex = NULL; - const char *id = SM2_DEFAULT_ID; - const char *keyfile = NULL; - const char *certfile = NULL; - FILE *keyfp = NULL; + char *id = SM2_DEFAULT_ID; + char *pubkeyfile = NULL; + char *certfile = NULL; + char *infile = NULL; + char *sigfile = NULL; + FILE *pubkeyfp = NULL; FILE *certfp = NULL; - X509_CERTIFICATE cert; + FILE *infp = stdin; + FILE *sigfp = NULL; SM2_KEY key; + X509_CERTIFICATE cert; SM2_SIGN_CTX verify_ctx; uint8_t buf[4096]; ssize_t len; uint8_t sig[SM2_MAX_SIGNATURE_SIZE]; size_t siglen; - if (argc < 2) { -bad: - fprintf(stderr, "%s : error options\n", prog); -help: - fprintf(stderr, "usage:\n"); - fprintf(stderr, " %s -sig hex -pubkey key.pem [-id str] < file\n", prog); - fprintf(stderr, " %s -sig hex -cert cert.pem [-id str] < file\n", prog); - fprintf(stderr, "\n"); - return 1; - } argc--; argv++; + while (argc > 1) { if (!strcmp(*argv, "-help")) { - goto help; - } else if (!strcmp(*argv, "-id")) { - if (--argc < 1) goto bad; - id = *(++argv); +help: + fprintf(stderr, "usage: %s {-pubkey pem | -cert pem} [-id str] [-in file] -sig file\n", prog); + return -1; + } else if (!strcmp(*argv, "-pubkey")) { if (--argc < 1) goto bad; - keyfile = *(++argv); - } else if (!strcmp(*argv, "-sig")) { - if (--argc < 1) goto bad; - sig_hex = *(++argv); + pubkeyfile = *(++argv); + } else if (!strcmp(*argv, "-cert")) { if (--argc < 1) goto bad; certfile = *(++argv); + + } else if (!strcmp(*argv, "-id")) { + if (--argc < 1) goto bad; + id = *(++argv); + + } else if (!strcmp(*argv, "-in")) { + if (--argc < 1) goto bad; + infile = *(++argv); + + } else if (!strcmp(*argv, "-sig")) { + if (--argc < 1) goto bad; + sigfile = *(++argv); + } else { goto help; } + argc--; argv++; } - if (!sig_hex || (!keyfile && !certfile) || (keyfile && certfile)) { - error_print(); - return -1; - } - if (strlen(sig_hex) > SM2_MAX_SIGNATURE_SIZE * 2 || strlen(sig_hex) % 2) { - error_print(); - return -1; - } - if (hex2bin(sig_hex, strlen(sig_hex), sig) != 1) { - error_print(); - return -1; - } - siglen = strlen(sig_hex)/2; - if (keyfile) { - if (!(keyfp = fopen(keyfile, "r"))) { + if (pubkeyfile) { + if (!(pubkeyfp = fopen(pubkeyfile, "r"))) { error_print(); return -1; } - if (sm2_public_key_info_from_pem(&key, keyfp) != 1) { + if (sm2_public_key_info_from_pem(&key, pubkeyfp) != 1) { error_print(); return -1; } - } else { + } else if (certfile) { if (!(certfp = fopen(certfile, "r"))) { error_print(); return -1; @@ -147,18 +110,46 @@ help: error_print(); return -1; } + } else { + fprintf(stderr, "%s: '-pubkey' or '-cert' option required\n", prog); + goto help; + } + + if (infile) { + if (!(infp = fopen(infile, "r"))) { + error_print(); + return -1; + } + } + + if (!sigfile) { + error_print(); + goto help; + } + if (!(sigfp = fopen(sigfile, "rb"))) { + error_print(); + return -1; + } + if ((siglen = fread(sig, 1, sizeof(sig), sigfp)) <= 0) { + error_print(); + return -1; } sm2_verify_init(&verify_ctx, &key, id); - while ((len = read(STDIN_FILENO, buf, sizeof(buf))) > 0) { + while ((len = fread(buf, 1, sizeof(buf), infp)) > 0) { sm2_verify_update(&verify_ctx, buf, len); } + if ((ret = sm2_verify_finish(&verify_ctx, sig, siglen)) < 0) { error_print(); return -1; } + fprintf(stdout, "verify : %s\n", ret == 1 ? "success" : "failure"); return ret == 1 ? 0 : -1; - return 1; + +bad: + fprintf(stderr, "%s: '%s' option value required\n", prog, *argv); + return -1; } diff --git a/tools/sm2view.c b/tools/sm2view.c deleted file mode 100644 index 48f25d98..00000000 --- a/tools/sm2view.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2020 - 2021 The GmSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include - -int main(void) -{ - SM2_KEY key; - - if (sm2_private_key_from_pem(&key, stdin) != 1) { - error_print(); - return -1; - } - sm2_key_print(stdout, &key, 0, 0); - sm2_public_key_info_to_pem(&key, stdout); - return 0; -} diff --git a/tools/sm3.c b/tools/sm3.c new file mode 100644 index 00000000..4a15a998 --- /dev/null +++ b/tools/sm3.c @@ -0,0 +1,122 @@ +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + + +int main(int argc, char **argv) +{ + char *prog = argv[0]; + char *pubkeyfile = NULL; + char *infile = NULL; + char *id = NULL; + FILE *pubkeyfp = NULL; + FILE *infp = stdin; + SM3_CTX sm3_ctx; + uint8_t dgst[32]; + uint8_t buf[4096]; + ssize_t len; + int i; + + argc--; + argv++; + + while (argc > 0) { + if (!strcmp(*argv, "-help")) { +help: + fprintf(stderr, "usage: %s [-pubkey pem [-id str]] [-in file]\n", prog); + fprintf(stderr, "usage: echo -n \"abc\" | %s\n", prog); + return -1; + + } else if (!strcmp(*argv, "-pubkey")) { + if (--argc < 1) goto bad; + pubkeyfile = *(++argv); + + } else if (!strcmp(*argv, "-id")) { + if (--argc < 1) goto bad; + id = *(++argv); + + } else if (!strcmp(*argv, "-in")) { + if (--argc < 1) goto bad; + infile = *(++argv); + + } else { + fprintf(stderr, "%s: illegal option '%s'\n", prog, *argv); + goto help; + } + + argc--; + argv++; + } + + sm3_init(&sm3_ctx); + + if (pubkeyfile) { + SM2_KEY sm2_key; + uint8_t z[32]; + + if (!(pubkeyfp = fopen(pubkeyfile, "r"))) { + error_print(); + return -1; + } + if (sm2_public_key_info_from_pem(&sm2_key, pubkeyfp) != 1) { + error_print(); + return -1; + } + if (!id) { + id = SM2_DEFAULT_ID; + } + + sm2_compute_z(z, (SM2_POINT *)&sm2_key, id); + sm3_update(&sm3_ctx, z, sizeof(z)); + + } else { + if (id) { + fprintf(stderr, "%s: option '-id' must be with '-pubkey'\n", prog); + goto help; + } + } + + if (infile) { + if (!(infp = fopen(infile, "r"))) { + error_print(); + return -1; + } + } + while ((len = fread(buf, 1, sizeof(buf), infp)) > 0) { + sm3_update(&sm3_ctx, buf, len); + } + + sm3_finish(&sm3_ctx, dgst); + for (i = 0; i < sizeof(dgst); i++) { + printf("%02x", dgst[i]); + } + printf("\n"); + + if (infile) { + fclose(infp); + } + return 0; + +bad: + fprintf(stderr, "%s: '%s' option value required\n", prog, *argv); + return -1; +} diff --git a/tools/sm3hmac.c b/tools/sm3hmac.c new file mode 100644 index 00000000..918e31c9 --- /dev/null +++ b/tools/sm3hmac.c @@ -0,0 +1,95 @@ +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + + +int main(int argc, char **argv) +{ + int ret = -1; + char *prog = argv[0]; + char *keyhex = NULL; + char *infile = NULL; + uint8_t key[32]; + size_t keylen; + FILE *in = stdin; + SM3_HMAC_CTX ctx; + unsigned char dgst[32]; + unsigned char buf[4096]; + size_t len; + + argc--; + argv++; + + while (argc > 0) { + if (!strcmp(*argv, "-help")) { +help: + fprintf(stderr, "usage: %s -keyhex hex [-in file]\n", prog); + return -1; + + } else if (!strcmp(*argv, "-keyhex")) { + if (--argc < 1) goto bad; + keyhex = *(++argv); + + } else if (!strcmp(*argv, "-in")) { + if (--argc < 1) goto bad; + infile = *(++argv); + + } else { + fprintf(stderr, "%s: illegal option '%s'\n", prog, *argv); + goto help; + } + + argc--; + argv++; + } + + if (!keyhex) { + fprintf(stderr, "%s: option '-keyhex' required\n", prog); + goto help; + } + if (strlen(keyhex) > sizeof(key) * 2) { + error_print(); + return -1; + } + if (hex_to_bytes(keyhex, strlen(keyhex), key, &keylen) != 1) { + error_print(); + return -1; + } + + sm3_hmac_init(&ctx, key, keylen); + + while ((len = fread(buf, 1, sizeof(buf), stdin)) > 0) { + sm3_hmac_update(&ctx, buf, len); + } + sm3_hmac_finish(&ctx, dgst); + + + format_bytes(stdout, 0, 0, "", dgst, sizeof(dgst)); + + memset(&ctx, 0, sizeof(ctx)); + memset(key, 0, sizeof(key)); + return 0; + +bad: + fprintf(stderr, "%s: '%s' option value required\n", prog, *argv); + return -1; +} diff --git a/tools/sm3sum.c b/tools/sm3sum.c deleted file mode 100644 index d038df2b..00000000 --- a/tools/sm3sum.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include - - -int main(int argc, char **argv) -{ - char *prog = argv[0]; - SM3_CTX ctx; - uint8_t dgst[32]; - uint8_t buf[4096]; - ssize_t len; - int i; - - if (argc > 1) { - fprintf(stderr, "usage: echo -n \"abc\" | %s\n", prog); - fprintf(stderr, " %s < path/to/file\n", prog); - return 0; - } - - sm3_init(&ctx); - while ((len = fread(buf, 1, sizeof(buf), stdin)) > 0) { - sm3_update(&ctx, buf, len); - } - sm3_finish(&ctx, dgst); - - for (i = 0; i < sizeof(dgst); i++) { - printf("%02x", dgst[i]); - } - printf("\n"); - return 0; -} diff --git a/tools/sm4speed.c b/tools/sm4speed.c index 935e596d..72098939 100644 --- a/tools/sm4speed.c +++ b/tools/sm4speed.c @@ -1,50 +1,17 @@ -/* ==================================================================== - * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ diff --git a/tools/tlcp_client.c b/tools/tlcp_client.c index fb18660d..aec54228 100644 --- a/tools/tlcp_client.c +++ b/tools/tlcp_client.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tools/tlcp_server.c b/tools/tlcp_server.c index 94ba1355..1885cc9d 100644 --- a/tools/tlcp_server.c +++ b/tools/tlcp_server.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tools/tls12_client.c b/tools/tls12_client.c index 6a850c4a..252d9b4f 100644 --- a/tools/tls12_client.c +++ b/tools/tls12_client.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include @@ -129,7 +97,7 @@ int main(int argc , char *argv[]) argv++; } - if (!host || !certfile || !keyfile) { + if (!host) { print_usage(prog); return -1; } diff --git a/tools/tls12_server.c b/tools/tls12_server.c index 0fcdb704..0f8c97d0 100644 --- a/tools/tls12_server.c +++ b/tools/tls12_server.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include @@ -135,7 +103,7 @@ int main(int argc , char *argv[]) memset(&conn, 0, sizeof(conn)); if (tls12_accept(&conn, port, certfp, &signkey, - certfp, verify_buf, 4096) != 1) { + NULL /* certfp */, verify_buf, 4096) != 1) { error_print(); return -1; } diff --git a/tools/tls13_client.c b/tools/tls13_client.c index 6dea4d88..b33e1271 100644 --- a/tools/tls13_client.c +++ b/tools/tls13_client.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include diff --git a/tools/tls13_server.c b/tools/tls13_server.c index 7c9877e0..65876e9c 100644 --- a/tools/tls13_server.c +++ b/tools/tls13_server.c @@ -1,49 +1,17 @@ -/* - * Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved. +/* + * Copyright 2014-2021 The GmSSL Project Authors. All Rights Reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * http://www.apache.org/licenses/LICENSE-2.0 * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the GmSSL Project. - * (http://gmssl.org/)" - * - * 4. The name "GmSSL Project" must not be used to endorse or promote - * products derived from this software without prior written - * permission. For written permission, please contact - * guanzhi1980@gmail.com. - * - * 5. Products derived from this software may not be called "GmSSL" - * nor may "GmSSL" appear in their names without prior written - * permission of the GmSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the GmSSL Project - * (http://gmssl.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include