Message ID | 1612777137-51067-6-git-send-email-yumeng18@huawei.com |
---|---|
State | New |
Headers | show |
Series | add ECDH and CURVE25519 algorithms support for Kunpeng 930 | expand |
Hi Meng, Thank you for the patch! Yet something to improve: [auto build test ERROR on cryptodev/master] [also build test ERROR on crypto/master v5.11-rc6 next-20210125] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch] url: https://github.com/0day-ci/linux/commits/Meng-Yu/add-ECDH-and-CURVE25519-algorithms-support-for-Kunpeng-930/20210209-073324 base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master config: sparc-randconfig-p002-20210209 (attached as .config) compiler: sparc-linux-gcc (GCC) 9.3.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/0day-ci/linux/commit/eeb0603ffdb2894db839c813cc66c4c08920d61b git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Meng-Yu/add-ECDH-and-CURVE25519-algorithms-support-for-Kunpeng-930/20210209-073324 git checkout eeb0603ffdb2894db839c813cc66c4c08920d61b # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=sparc If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>): In file included from crypto/testmgr.c:73: >> crypto/testmgr.h:2304:2: error: expected '}' before ';' token 2304 | }; | ^ crypto/testmgr.h:2264:59: note: to match this '{' 2264 | static const struct kpp_testvec ecdh_p192_tv_template[] = { | ^ crypto/testmgr.h:2264:33: warning: 'ecdh_p192_tv_template' defined but not used [-Wunused-const-variable=] 2264 | static const struct kpp_testvec ecdh_p192_tv_template[] = { | ^~~~~~~~~~~~~~~~~~~~~ crypto/testmgr.h:1039:33: warning: 'curve25519_tv_template' defined but not used [-Wunused-const-variable=] 1039 | static const struct kpp_testvec curve25519_tv_template[] = { | ^~~~~~~~~~~~~~~~~~~~~~ crypto/testmgr.h:818:33: warning: 'dh_tv_template' defined but not used [-Wunused-const-variable=] 818 | static const struct kpp_testvec dh_tv_template[] = { | ^~~~~~~~~~~~~~ crypto/testmgr.h:726:38: warning: 'pkcs1pad_rsa_tv_template' defined but not used [-Wunused-const-variable=] 726 | static const struct akcipher_testvec pkcs1pad_rsa_tv_template[] = { | ^~~~~~~~~~~~~~~~~~~~~~~~ crypto/testmgr.h:572:38: warning: 'ecrdsa_tv_template' defined but not used [-Wunused-const-variable=] 572 | static const struct akcipher_testvec ecrdsa_tv_template[] = { | ^~~~~~~~~~~~~~~~~~ crypto/testmgr.h:182:38: warning: 'rsa_tv_template' defined but not used [-Wunused-const-variable=] 182 | static const struct akcipher_testvec rsa_tv_template[] = { | ^~~~~~~~~~~~~~~ crypto/testmgr.h:177:19: warning: 'zeroed_string' defined but not used [-Wunused-const-variable=] 177 | static const char zeroed_string[48]; | ^~~~~~~~~~~~~ vim +2304 crypto/testmgr.h 2263 2264 static const struct kpp_testvec ecdh_p192_tv_template[] = { 2265 { 2266 #ifndef CONFIG_CRYPTO_FIPS 2267 .secret = 2268 #ifdef __LITTLE_ENDIAN 2269 "\x02\x00" /* type */ 2270 "\x1e\x00" /* len */ 2271 "\x18\x00" /* key_size */ 2272 #else 2273 "\x00\x02" /* type */ 2274 "\x00\x1e" /* len */ 2275 "\x00\x18" /* key_size */ 2276 #endif 2277 "\xb5\x05\xb1\x71\x1e\xbf\x8c\xda" 2278 "\x4e\x19\x1e\x62\x1f\x23\x23\x31" 2279 "\x36\x1e\xd3\x84\x2f\xcc\x21\x72", 2280 .b_public = 2281 "\xc3\xba\x67\x4b\x71\xec\xd0\x76" 2282 "\x7a\x99\x75\x64\x36\x13\x9a\x94" 2283 "\x5d\x8b\xdc\x60\x90\x91\xfd\x3f" 2284 "\xb0\x1f\x8a\x0a\x68\xc6\x88\x6e" 2285 "\x83\x87\xdd\x67\x09\xf8\x8d\x96" 2286 "\x07\xd6\xbd\x1c\xe6\x8d\x9d\x67", 2287 .expected_a_public = 2288 "\x1a\x04\xdb\xa5\xe1\xdd\x4e\x79" 2289 "\xa3\xe6\xef\x0e\x5c\x80\x49\x85" 2290 "\xfa\x78\xb4\xef\x49\xbd\x4c\x7c" 2291 "\x22\x90\x21\x02\xf9\x1b\x81\x5d" 2292 "\x0c\x8a\xa8\x98\xd6\x27\x69\x88" 2293 "\x5e\xbc\x94\xd8\x15\x9e\x21\xce", 2294 .expected_ss = 2295 "\xf4\x57\xcc\x4f\x1f\x4e\x31\xcc" 2296 "\xe3\x40\x60\xc8\x06\x93\xc6\x2e" 2297 "\x99\x80\x81\x28\xaf\xc5\x51\x74", 2298 .secret_size = 32, 2299 .b_public_size = 48, 2300 .expected_a_public_size = 48, 2301 .expected_ss_size = 24 2302 } 2303 #endif > 2304 }; 2305 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Hi Meng, Thank you for the patch! Yet something to improve: [auto build test ERROR on cryptodev/master] [also build test ERROR on crypto/master v5.11-rc6 next-20210125] [cannot apply to bluetooth/master] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch] url: https://github.com/0day-ci/linux/commits/Meng-Yu/add-ECDH-and-CURVE25519-algorithms-support-for-Kunpeng-930/20210209-073324 base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master config: powerpc64-randconfig-r015-20210209 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project c9439ca36342fb6013187d0a69aef92736951476) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install powerpc64 cross compiling tool for clang build # apt-get install binutils-powerpc64-linux-gnu # https://github.com/0day-ci/linux/commit/eeb0603ffdb2894db839c813cc66c4c08920d61b git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Meng-Yu/add-ECDH-and-CURVE25519-algorithms-support-for-Kunpeng-930/20210209-073324 git checkout eeb0603ffdb2894db839c813cc66c4c08920d61b # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=powerpc64 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>): In file included from crypto/testmgr.c:73: >> crypto/testmgr.h:2304:2: error: expected '}' }; ^ crypto/testmgr.h:2264:59: note: to match this '{' static const struct kpp_testvec ecdh_p192_tv_template[] = { ^ >> crypto/testmgr.c:4917:11: error: invalid application of 'sizeof' to an incomplete type 'const struct kpp_testvec []' .kpp = __VECS(ecdh_p192_tv_template) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ crypto/testmgr.c:4149:22: note: expanded from macro '__VECS' #define __VECS(tv) { ____VECS(tv) } ^~~~~~~~~~~~ crypto/testmgr.c:4148:43: note: expanded from macro '____VECS' #define ____VECS(tv) .vecs = tv, .count = ARRAY_SIZE(tv) ^~~~~~~~~~~~~~ include/linux/kernel.h:49:32: note: expanded from macro 'ARRAY_SIZE' #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) ^~~~~ >> crypto/testmgr.c:5515:18: error: invalid application of 'sizeof' to an incomplete type 'const struct alg_test_desc []' for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) { ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/kernel.h:49:32: note: expanded from macro 'ARRAY_SIZE' #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) ^~~~~ crypto/testmgr.c:5558:12: error: invalid application of 'sizeof' to an incomplete type 'const struct alg_test_desc []' int end = ARRAY_SIZE(alg_test_descs); ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/kernel.h:49:32: note: expanded from macro 'ARRAY_SIZE' #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) ^~~~~ 4 errors generated. vim +2304 crypto/testmgr.h 2263 2264 static const struct kpp_testvec ecdh_p192_tv_template[] = { 2265 { 2266 #ifndef CONFIG_CRYPTO_FIPS 2267 .secret = 2268 #ifdef __LITTLE_ENDIAN 2269 "\x02\x00" /* type */ 2270 "\x1e\x00" /* len */ 2271 "\x18\x00" /* key_size */ 2272 #else 2273 "\x00\x02" /* type */ 2274 "\x00\x1e" /* len */ 2275 "\x00\x18" /* key_size */ 2276 #endif 2277 "\xb5\x05\xb1\x71\x1e\xbf\x8c\xda" 2278 "\x4e\x19\x1e\x62\x1f\x23\x23\x31" 2279 "\x36\x1e\xd3\x84\x2f\xcc\x21\x72", 2280 .b_public = 2281 "\xc3\xba\x67\x4b\x71\xec\xd0\x76" 2282 "\x7a\x99\x75\x64\x36\x13\x9a\x94" 2283 "\x5d\x8b\xdc\x60\x90\x91\xfd\x3f" 2284 "\xb0\x1f\x8a\x0a\x68\xc6\x88\x6e" 2285 "\x83\x87\xdd\x67\x09\xf8\x8d\x96" 2286 "\x07\xd6\xbd\x1c\xe6\x8d\x9d\x67", 2287 .expected_a_public = 2288 "\x1a\x04\xdb\xa5\xe1\xdd\x4e\x79" 2289 "\xa3\xe6\xef\x0e\x5c\x80\x49\x85" 2290 "\xfa\x78\xb4\xef\x49\xbd\x4c\x7c" 2291 "\x22\x90\x21\x02\xf9\x1b\x81\x5d" 2292 "\x0c\x8a\xa8\x98\xd6\x27\x69\x88" 2293 "\x5e\xbc\x94\xd8\x15\x9e\x21\xce", 2294 .expected_ss = 2295 "\xf4\x57\xcc\x4f\x1f\x4e\x31\xcc" 2296 "\xe3\x40\x60\xc8\x06\x93\xc6\x2e" 2297 "\x99\x80\x81\x28\xaf\xc5\x51\x74", 2298 .secret_size = 32, 2299 .b_public_size = 48, 2300 .expected_a_public_size = 48, 2301 .expected_ss_size = 24 2302 } 2303 #endif > 2304 }; 2305 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff --git a/crypto/ecdh.c b/crypto/ecdh.c index 96f80c8..04a427b 100644 --- a/crypto/ecdh.c +++ b/crypto/ecdh.c @@ -23,33 +23,16 @@ static inline struct ecdh_ctx *ecdh_get_ctx(struct crypto_kpp *tfm) return kpp_tfm_ctx(tfm); } -static unsigned int ecdh_supported_curve(unsigned int curve_id) -{ - switch (curve_id) { - case ECC_CURVE_NIST_P192: return ECC_CURVE_NIST_P192_DIGITS; - case ECC_CURVE_NIST_P256: return ECC_CURVE_NIST_P256_DIGITS; - default: return 0; - } -} - static int ecdh_set_secret(struct crypto_kpp *tfm, const void *buf, unsigned int len) { struct ecdh_ctx *ctx = ecdh_get_ctx(tfm); struct ecdh params; - unsigned int ndigits; if (crypto_ecdh_decode_key(buf, len, ¶ms) < 0 || - params.key_size > sizeof(ctx->private_key)) + params.key_size > sizeof(u64) * ctx->ndigits) return -EINVAL; - ndigits = ecdh_supported_curve(params.curve_id); - if (!ndigits) - return -EINVAL; - - ctx->curve_id = params.curve_id; - ctx->ndigits = ndigits; - if (!params.key || !params.key_size) return ecc_gen_privkey(ctx->curve_id, ctx->ndigits, ctx->private_key); @@ -140,13 +123,24 @@ static unsigned int ecdh_max_size(struct crypto_kpp *tfm) return ctx->ndigits << (ECC_DIGITS_TO_BYTES_SHIFT + 1); } -static struct kpp_alg ecdh = { +static int ecdh_nist_p192_init_tfm(struct crypto_kpp *tfm) +{ + struct ecdh_ctx *ctx = ecdh_get_ctx(tfm); + + ctx->curve_id = ECC_CURVE_NIST_P192; + ctx->ndigits = ECC_CURVE_NIST_P192_DIGITS; + + return 0; +} + +static struct kpp_alg ecdh_nist_p192 = { .set_secret = ecdh_set_secret, .generate_public_key = ecdh_compute_value, .compute_shared_secret = ecdh_compute_value, .max_size = ecdh_max_size, + .init = ecdh_nist_p192_init_tfm, .base = { - .cra_name = "ecdh", + .cra_name = "ecdh-nist-p192", .cra_driver_name = "ecdh-generic", .cra_priority = 100, .cra_module = THIS_MODULE, @@ -154,14 +148,48 @@ static struct kpp_alg ecdh = { }, }; +static int ecdh_nist_p256_init_tfm(struct crypto_kpp *tfm) +{ + struct ecdh_ctx *ctx = ecdh_get_ctx(tfm); + + ctx->curve_id = ECC_CURVE_NIST_P256; + ctx->ndigits = ECC_CURVE_NIST_P256_DIGITS; + + return 0; +} + +static struct kpp_alg ecdh_nist_p256 = { + .set_secret = ecdh_set_secret, + .generate_public_key = ecdh_compute_value, + .compute_shared_secret = ecdh_compute_value, + .max_size = ecdh_max_size, + .init = ecdh_nist_p256_init_tfm, + .base = { + .cra_name = "ecdh-nist-p256", + .cra_driver_name = "ecdh-generic", + .cra_priority = 100, + .cra_module = THIS_MODULE, + .cra_ctxsize = sizeof(struct ecdh_ctx), + }, +}; + +static bool ecdh_nist_p192_registered; + static int ecdh_init(void) { - return crypto_register_kpp(&ecdh); + int ret; + + ret = crypto_register_kpp(&ecdh_nist_p192); + ecdh_nist_p192_registered = ret == 0; + + return crypto_register_kpp(&ecdh_nist_p256); } static void ecdh_exit(void) { - crypto_unregister_kpp(&ecdh); + if (ecdh_nist_p192_registered) + crypto_unregister_kpp(&ecdh_nist_p192); + crypto_unregister_kpp(&ecdh_nist_p256); } subsys_initcall(ecdh_init); diff --git a/crypto/ecdh_helper.c b/crypto/ecdh_helper.c index 66fcb2e..c79696f 100644 --- a/crypto/ecdh_helper.c +++ b/crypto/ecdh_helper.c @@ -10,7 +10,7 @@ #include <crypto/ecdh.h> #include <crypto/kpp.h> -#define ECDH_KPP_SECRET_MIN_SIZE (sizeof(struct kpp_secret) + 2 * sizeof(short)) +#define ECDH_KPP_SECRET_MIN_SIZE (sizeof(struct kpp_secret) + sizeof(short)) static inline u8 *ecdh_pack_data(void *dst, const void *src, size_t sz) { @@ -46,7 +46,6 @@ int crypto_ecdh_encode_key(char *buf, unsigned int len, return -EINVAL; ptr = ecdh_pack_data(ptr, &secret, sizeof(secret)); - ptr = ecdh_pack_data(ptr, ¶ms->curve_id, sizeof(params->curve_id)); ptr = ecdh_pack_data(ptr, ¶ms->key_size, sizeof(params->key_size)); ecdh_pack_data(ptr, params->key, params->key_size); @@ -67,7 +66,6 @@ int crypto_ecdh_decode_key(const char *buf, unsigned int len, if (secret.type != CRYPTO_KPP_SECRET_TYPE_ECDH) return -EINVAL; - ptr = ecdh_unpack_data(¶ms->curve_id, ptr, sizeof(params->curve_id)); ptr = ecdh_unpack_data(¶ms->key_size, ptr, sizeof(params->key_size)); if (secret.len != crypto_ecdh_key_len(params)) return -EINVAL; diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 1a4103b..b890ac5 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -4910,11 +4910,18 @@ static const struct alg_test_desc alg_test_descs[] = { } }, { #endif - .alg = "ecdh", + .alg = "ecdh-nist-p192", .test = alg_test_kpp, .fips_allowed = 1, .suite = { - .kpp = __VECS(ecdh_tv_template) + .kpp = __VECS(ecdh_p192_tv_template) + } + }, { + .alg = "ecdh-nist-p256", + .test = alg_test_kpp, + .fips_allowed = 1, + .suite = { + .kpp = __VECS(ecdh_p256_tv_template) } }, { .alg = "ecrdsa", diff --git a/crypto/testmgr.h b/crypto/testmgr.h index 99aca08..85bf54e 100644 --- a/crypto/testmgr.h +++ b/crypto/testmgr.h @@ -2261,19 +2261,17 @@ static const struct kpp_testvec curve25519_tv_template[] = { } }; -static const struct kpp_testvec ecdh_tv_template[] = { +static const struct kpp_testvec ecdh_p192_tv_template[] = { { #ifndef CONFIG_CRYPTO_FIPS .secret = #ifdef __LITTLE_ENDIAN "\x02\x00" /* type */ - "\x20\x00" /* len */ - "\x01\x00" /* curve_id */ + "\x1e\x00" /* len */ "\x18\x00" /* key_size */ #else "\x00\x02" /* type */ - "\x00\x20" /* len */ - "\x00\x01" /* curve_id */ + "\x00\x1e" /* len */ "\x00\x18" /* key_size */ #endif "\xb5\x05\xb1\x71\x1e\xbf\x8c\xda" @@ -2301,18 +2299,20 @@ static const struct kpp_testvec ecdh_tv_template[] = { .b_public_size = 48, .expected_a_public_size = 48, .expected_ss_size = 24 - }, { + } #endif +}; + +static const struct kpp_testvec ecdh_p256_tv_template[] = { + { .secret = #ifdef __LITTLE_ENDIAN "\x02\x00" /* type */ - "\x28\x00" /* len */ - "\x02\x00" /* curve_id */ + "\x26\x00" /* len */ "\x20\x00" /* key_size */ #else "\x00\x02" /* type */ - "\x00\x28" /* len */ - "\x00\x02" /* curve_id */ + "\x00\x26" /* len */ "\x00\x20" /* key_size */ #endif "\x24\xd1\x21\xeb\xe5\xcf\x2d\x83" @@ -2350,25 +2350,21 @@ static const struct kpp_testvec ecdh_tv_template[] = { .secret = #ifdef __LITTLE_ENDIAN "\x02\x00" /* type */ - "\x08\x00" /* len */ - "\x02\x00" /* curve_id */ + "\x06\x00" /* len */ "\x00\x00", /* key_size */ #else "\x00\x02" /* type */ - "\x00\x08" /* len */ - "\x00\x02" /* curve_id */ + "\x00\x06" /* len */ "\x00\x00", /* key_size */ #endif .b_secret = #ifdef __LITTLE_ENDIAN "\x02\x00" /* type */ - "\x28\x00" /* len */ - "\x02\x00" /* curve_id */ + "\x26\x00" /* len */ "\x20\x00" /* key_size */ #else "\x00\x02" /* type */ - "\x00\x28" /* len */ - "\x00\x02" /* curve_id */ + "\x00\x26" /* len */ "\x00\x20" /* key_size */ #endif "\x24\xd1\x21\xeb\xe5\xcf\x2d\x83" diff --git a/include/crypto/ecdh.h b/include/crypto/ecdh.h index a5b805b..deaaa48 100644 --- a/include/crypto/ecdh.h +++ b/include/crypto/ecdh.h @@ -29,12 +29,10 @@ /** * struct ecdh - define an ECDH private key * - * @curve_id: ECC curve the key is based on. * @key: Private ECDH key * @key_size: Size of the private ECDH key */ struct ecdh { - unsigned short curve_id; char *key; unsigned short key_size; };