kpp.h (cf40a76e7d5874bb25f4404eecc58a2e033af885) | kpp.h (cac5818c25d0423bda73e2b6997404ed0a7ed9e3) |
---|---|
1/* 2 * Key-agreement Protocol Primitives (KPP) 3 * 4 * Copyright (c) 2016, Intel Corporation 5 * Authors: Salvatore Benedetto <salvatore.benedetto@intel.com> 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the Free --- 254 unchanged lines hidden (view full) --- 263 * @len: specify the len of the secret, include the header, that 264 * follows the struct 265 */ 266struct kpp_secret { 267 unsigned short type; 268 unsigned short len; 269}; 270 | 1/* 2 * Key-agreement Protocol Primitives (KPP) 3 * 4 * Copyright (c) 2016, Intel Corporation 5 * Authors: Salvatore Benedetto <salvatore.benedetto@intel.com> 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the Free --- 254 unchanged lines hidden (view full) --- 263 * @len: specify the len of the secret, include the header, that 264 * follows the struct 265 */ 266struct kpp_secret { 267 unsigned short type; 268 unsigned short len; 269}; 270 |
271static inline void crypto_stat_kpp_set_secret(struct crypto_kpp *tfm, int ret) 272{ 273#ifdef CONFIG_CRYPTO_STATS 274 if (ret) 275 atomic_inc(&tfm->base.__crt_alg->kpp_err_cnt); 276 else 277 atomic_inc(&tfm->base.__crt_alg->setsecret_cnt); 278#endif 279} 280 281static inline void crypto_stat_kpp_generate_public_key(struct kpp_request *req, 282 int ret) 283{ 284#ifdef CONFIG_CRYPTO_STATS 285 struct crypto_kpp *tfm = crypto_kpp_reqtfm(req); 286 287 if (ret) 288 atomic_inc(&tfm->base.__crt_alg->kpp_err_cnt); 289 else 290 atomic_inc(&tfm->base.__crt_alg->generate_public_key_cnt); 291#endif 292} 293 294static inline void crypto_stat_kpp_compute_shared_secret(struct kpp_request *req, 295 int ret) 296{ 297#ifdef CONFIG_CRYPTO_STATS 298 struct crypto_kpp *tfm = crypto_kpp_reqtfm(req); 299 300 if (ret) 301 atomic_inc(&tfm->base.__crt_alg->kpp_err_cnt); 302 else 303 atomic_inc(&tfm->base.__crt_alg->compute_shared_secret_cnt); 304#endif 305} 306 |
|
271/** 272 * crypto_kpp_set_secret() - Invoke kpp operation 273 * 274 * Function invokes the specific kpp operation for a given alg. 275 * 276 * @tfm: tfm handle 277 * @buffer: Buffer holding the packet representation of the private 278 * key. The structure of the packet key depends on the particular 279 * KPP implementation. Packing and unpacking helpers are provided 280 * for ECDH and DH (see the respective header files for those 281 * implementations). 282 * @len: Length of the packet private key buffer. 283 * 284 * Return: zero on success; error code in case of error 285 */ 286static inline int crypto_kpp_set_secret(struct crypto_kpp *tfm, 287 const void *buffer, unsigned int len) 288{ 289 struct kpp_alg *alg = crypto_kpp_alg(tfm); | 307/** 308 * crypto_kpp_set_secret() - Invoke kpp operation 309 * 310 * Function invokes the specific kpp operation for a given alg. 311 * 312 * @tfm: tfm handle 313 * @buffer: Buffer holding the packet representation of the private 314 * key. The structure of the packet key depends on the particular 315 * KPP implementation. Packing and unpacking helpers are provided 316 * for ECDH and DH (see the respective header files for those 317 * implementations). 318 * @len: Length of the packet private key buffer. 319 * 320 * Return: zero on success; error code in case of error 321 */ 322static inline int crypto_kpp_set_secret(struct crypto_kpp *tfm, 323 const void *buffer, unsigned int len) 324{ 325 struct kpp_alg *alg = crypto_kpp_alg(tfm); |
326 int ret; |
|
290 | 327 |
291 return alg->set_secret(tfm, buffer, len); | 328 ret = alg->set_secret(tfm, buffer, len); 329 crypto_stat_kpp_set_secret(tfm, ret); 330 return ret; |
292} 293 294/** 295 * crypto_kpp_generate_public_key() - Invoke kpp operation 296 * 297 * Function invokes the specific kpp operation for generating the public part 298 * for a given kpp algorithm. 299 * 300 * To generate a private key, the caller should use a random number generator. 301 * The output of the requested length serves as the private key. 302 * 303 * @req: kpp key request 304 * 305 * Return: zero on success; error code in case of error 306 */ 307static inline int crypto_kpp_generate_public_key(struct kpp_request *req) 308{ 309 struct crypto_kpp *tfm = crypto_kpp_reqtfm(req); 310 struct kpp_alg *alg = crypto_kpp_alg(tfm); | 331} 332 333/** 334 * crypto_kpp_generate_public_key() - Invoke kpp operation 335 * 336 * Function invokes the specific kpp operation for generating the public part 337 * for a given kpp algorithm. 338 * 339 * To generate a private key, the caller should use a random number generator. 340 * The output of the requested length serves as the private key. 341 * 342 * @req: kpp key request 343 * 344 * Return: zero on success; error code in case of error 345 */ 346static inline int crypto_kpp_generate_public_key(struct kpp_request *req) 347{ 348 struct crypto_kpp *tfm = crypto_kpp_reqtfm(req); 349 struct kpp_alg *alg = crypto_kpp_alg(tfm); |
350 int ret; |
|
311 | 351 |
312 return alg->generate_public_key(req); | 352 ret = alg->generate_public_key(req); 353 crypto_stat_kpp_generate_public_key(req, ret); 354 return ret; |
313} 314 315/** 316 * crypto_kpp_compute_shared_secret() - Invoke kpp operation 317 * 318 * Function invokes the specific kpp operation for computing the shared secret 319 * for a given kpp algorithm. 320 * 321 * @req: kpp key request 322 * 323 * Return: zero on success; error code in case of error 324 */ 325static inline int crypto_kpp_compute_shared_secret(struct kpp_request *req) 326{ 327 struct crypto_kpp *tfm = crypto_kpp_reqtfm(req); 328 struct kpp_alg *alg = crypto_kpp_alg(tfm); | 355} 356 357/** 358 * crypto_kpp_compute_shared_secret() - Invoke kpp operation 359 * 360 * Function invokes the specific kpp operation for computing the shared secret 361 * for a given kpp algorithm. 362 * 363 * @req: kpp key request 364 * 365 * Return: zero on success; error code in case of error 366 */ 367static inline int crypto_kpp_compute_shared_secret(struct kpp_request *req) 368{ 369 struct crypto_kpp *tfm = crypto_kpp_reqtfm(req); 370 struct kpp_alg *alg = crypto_kpp_alg(tfm); |
371 int ret; |
|
329 | 372 |
330 return alg->compute_shared_secret(req); | 373 ret = alg->compute_shared_secret(req); 374 crypto_stat_kpp_compute_shared_secret(req, ret); 375 return ret; |
331} 332 333/** 334 * crypto_kpp_maxsize() - Get len for output buffer 335 * 336 * Function returns the output buffer size required for a given key. 337 * Function assumes that the key is already set in the transformation. If this 338 * function is called without a setkey or with a failed setkey, you will end up --- 12 unchanged lines hidden --- | 376} 377 378/** 379 * crypto_kpp_maxsize() - Get len for output buffer 380 * 381 * Function returns the output buffer size required for a given key. 382 * Function assumes that the key is already set in the transformation. If this 383 * function is called without a setkey or with a failed setkey, you will end up --- 12 unchanged lines hidden --- |