From 657275d11b10dc21ca78a2cbb3ce97ced2756987 Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Tue, 14 Feb 2017 16:42:23 +0800 Subject: [PATCH] add commons --- crypto/objects/objects.txt | 128 ++++++++++++++++++++++++++++++++++- include/internal/byteorder.h | 76 +++++++++++++++++++++ 2 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 include/internal/byteorder.h diff --git a/crypto/objects/objects.txt b/crypto/objects/objects.txt index fc0781d1..57dbd66a 100644 --- a/crypto/objects/objects.txt +++ b/crypto/objects/objects.txt @@ -76,7 +76,9 @@ X9-62_primeCurve 4 : prime239v1 X9-62_primeCurve 5 : prime239v2 X9-62_primeCurve 6 : prime239v3 X9-62_primeCurve 7 : prime256v1 -!Alias id-ecSigType ansi-X9-62 4 +# GMSSL export ecdsa type +#!Alias id-ecSigType ansi-X9-62 4 +ansi-X9-62 4 : id-ecSigType !global X9-62_id-ecSigType 1 : ecdsa-with-SHA1 X9-62_id-ecSigType 2 : ecdsa-with-Recommended @@ -1414,7 +1416,9 @@ ISO-US 10046 2 1 : dhpublicnumber : X9.42 DH # ECDH schemes from RFC5753 !Alias x9-63-scheme 1 3 133 16 840 63 0 -!Alias secg-scheme certicom-arc 1 +# GMSSL export secg-scheme +# !Alias secg-scheme certicom-arc 1 +certicom-arc 1 : secg-scheme x9-63-scheme 2 : dhSinglePass-stdDH-sha1kdf-scheme secg-scheme 11 0 : dhSinglePass-stdDH-sha224kdf-scheme @@ -1483,3 +1487,123 @@ id-pkinit 5 : pkInitKDC : Signing KDC Response : AuthSRP : auth-srp : AuthNULL : auth-null +# GmSSL SECG ECIES OID +secg-scheme 7 : ecies-recommendedParameters +secg-scheme 8 : ecies-specifiedParameters +secg-scheme 17 0 : x9-63-kdf +secg-scheme 17 1 : nist-concatenation-kdf +secg-scheme 17 2 : tls-kdf +secg-scheme 17 3 : ikev2-kdf +secg-scheme 18 : xor-in-ecies +secg-scheme 19 : tdes-cbc-in-ecies +secg-scheme 20 0 : aes128-cbc-in-ecies +secg-scheme 20 1 : aes192-cbc-in-ecies +secg-scheme 20 2 : aes256-cbc-in-ecies +secg-scheme 21 0 : aes128-ctr-in-ecies +secg-scheme 21 1 : aes192-ctr-in-ecies +secg-scheme 21 2 : aes256-ctr-in-ecies +secg-scheme 22 : hmac-full-ecies +secg-scheme 23 : hmac-half-ecies +secg-scheme 24 0 : cmac-aes128-ecies +secg-scheme 24 1 : cmac-aes192-ecies +secg-scheme 24 2 : cmac-aes256-ecies + +# No NID for CBC-MAC + : CBC-MAC : cbc-mac + +# GmSSL SM OID +member-body 156 : ISO-CN : ISO CN Member Body +ISO-CN 10197 : oscca +oscca 1 : sm-scheme + +sm-scheme 101 1 : SM6-ECB : sm6-ecb +sm-scheme 101 2 : SM6-CBC : sm6-cbc +!Cname sm6-ofb128 +sm-scheme 101 3 : SM6-OFB : sm6-ofb +!Cname sm6-cfb128 +sm-scheme 101 4 : SM6-CFB : sm6-cfb + +sm-scheme 102 1 : SM1-ECB : sm1-ecb +sm-scheme 102 2 : SM1-CBC : sm1-cbc +!Cname sm1-ofb128 +sm-scheme 102 3 : SM1-OFB : sm1-ofb +!Cname sm1-cfb128 +sm-scheme 102 4 : SM1-CFB : sm1-cfb +sm-scheme 102 5 : SM1-CFB1 : sm1-cfb1 +sm-scheme 102 6 : SM1-CFB8 : sm1-cfb8 + +sm-scheme 103 1 : SSF33-ECB : ssf33-ecb +sm-scheme 103 2 : SSF33-CBC : ssf33-cbc +!Cname ssf33-ofb128 +sm-scheme 103 3 : SSF33-OFB : ssf33-ofb +!Cname ssf33-cfb128 +sm-scheme 103 4 : SSF33-CFB : ssf33-cfb +sm-scheme 103 5 : SSF33-CFB1 : ssf33-cfb1 +sm-scheme 103 6 : SSF33-CFB8 : ssf33-cfb8 + +sm-scheme 104 1 : SMS4-ECB : sms4-ecb +sm-scheme 104 2 : SMS4-CBC : sms4-cbc +!Cname sms4-ofb128 +sm-scheme 104 3 : SMS4-OFB : sms4-ofb +!Cname sms4-cfb128 +sm-scheme 104 4 : SMS4-CFB : sms4-cfb +sm-scheme 104 5 : SMS4-CFB1 : sms4-cfb1 +sm-scheme 104 6 : SMS4-CFB8 : sms4-cfb8 +sm-scheme 104 7 : SMS4-CTR : sms4-ctr +sm-scheme 104 8 : SMS4-GCM : sms4-gcm +sm-scheme 104 9 : SMS4-CCM : sms4-ccm +sm-scheme 104 10 : SMS4-XTS : sms4-xts +sm-scheme 104 11 : SMS4-WRAP : sms4-wrap +sm-scheme 104 12 : SMS4-WRAP-PAD : sms4-wrap-pad +sm-scheme 104 100 : SMS4-OCB : sms4-ocb + +!Alias sm7 sm-scheme 105 + +!Alias sm8 sm-scheme 106 + +sm-scheme 201 : SM5 : sm5 + +sm-scheme 301 : sm2p256v1 +sm-scheme 301 1 : sm2sign +sm-scheme 301 2 : sm2keyagreement +sm-scheme 301 3 : sm2encrypt +sm2encrypt 1 : sm2encrypt-recommendedParameters +sm2encrypt 2 : sm2encrypt-specifiedParameters + +sm-scheme 302 : id-sm9PublicKey +sm-scheme 302 1 : sm9sign +sm-scheme 302 2 : sm9keyagreement +sm-scheme 302 3 : sm9encrypt + +sm-scheme 401 : SM3 : sm3 +sm-scheme 401 2 : HMAC-SM3 : hmac-sm3 +sm-scheme 501 : SM2Sign-with-SM3 : sm2sign-with-sm3 +sm-scheme 502 : SM2Sign-with-SHA1 : sm2sign-with-sha1 +sm-scheme 503 : SM2Sign-with-SHA256 : sm2sign-with-sha256 +sm-scheme 504 : SM2Sign-with-SHA511 : sm2sign-with-sha512 +sm-scheme 505 : SM2Sign-with-SHA224 : sm2sign-with-sha224 +sm-scheme 506 : SM2Sign-with-SHA384 : sm2sign-with-sha384 +sm-scheme 507 : SM2Sign-with-RMD160 : sm2sign-with-rmd160 + +sm-scheme 301 101 : wapip192v1 + +# GmSSL ZUC OID +sm-scheme 800 : ZUC : zuc + + +# IBCS1 +!Alias ibcs1 ISO-US 1 114334 1 +ibcs1 2 1 : bfibe +ibcs1 2 2 : bb1 +# 1 tate, 2 weil, 3 ate, 4 r-ate +ibcs1 1 1 : type1curve +ibcs1 1 2 : type2curve +ibcs1 1 3 : type3curve +ibcs1 1 4 : type4curve + +ibcs1 3 1 : tate-pairing +ibcs1 3 2 : weil-pairing +ibcs1 3 3 : ate-pairing +ibcs1 3 4 : r-ate-pairing + +# CPK OID diff --git a/include/internal/byteorder.h b/include/internal/byteorder.h new file mode 100644 index 00000000..cc541ba1 --- /dev/null +++ b/include/internal/byteorder.h @@ -0,0 +1,76 @@ +/* ==================================================================== + * Copyright (c) 2014 - 2017 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. + * ==================================================================== + */ + +#ifndef HEADER_BYTEORDER_H +#define HEADER_BYTEORDER_H + + +#ifdef CPU_BIGENDIAN + +#define cpu_to_be16(v) (v) +#define cpu_to_be32(v) (v) +#define be16_to_cpu(v) (v) +#define be32_to_cpu(v) (v) + +#else + +#define cpu_to_le16(v) (v) +#define cpu_to_le32(v) (v) +#define le16_to_cpu(v) (v) +#define le32_to_cpu(v) (v) + +#define cpu_to_be16(v) (((v)<< 8) | ((v)>>8)) +#define cpu_to_be32(v) (((v)>>24) | (((v)>>8)&0xff00) | (((v)<<8)&0xff0000) | ((v)<<24)) +#define be16_to_cpu(v) cpu_to_be16(v) +#define be32_to_cpu(v) cpu_to_be32(v) + +#endif + +#endif +