Path: blob/main/contrib/bearssl/src/ec/ec_all_m15.c
39507 views
/*1* Copyright (c) 2017 Thomas Pornin <[email protected]>2*3* Permission is hereby granted, free of charge, to any person obtaining4* a copy of this software and associated documentation files (the5* "Software"), to deal in the Software without restriction, including6* without limitation the rights to use, copy, modify, merge, publish,7* distribute, sublicense, and/or sell copies of the Software, and to8* permit persons to whom the Software is furnished to do so, subject to9* the following conditions:10*11* The above copyright notice and this permission notice shall be12* included in all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,15* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF16* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND17* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS18* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN19* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN20* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*/2324#include "inner.h"2526static const unsigned char *27api_generator(int curve, size_t *len)28{29switch (curve) {30case BR_EC_secp256r1:31return br_ec_p256_m15.generator(curve, len);32case BR_EC_curve25519:33return br_ec_c25519_m15.generator(curve, len);34default:35return br_ec_prime_i15.generator(curve, len);36}37}3839static const unsigned char *40api_order(int curve, size_t *len)41{42switch (curve) {43case BR_EC_secp256r1:44return br_ec_p256_m15.order(curve, len);45case BR_EC_curve25519:46return br_ec_c25519_m15.order(curve, len);47default:48return br_ec_prime_i15.order(curve, len);49}50}5152static size_t53api_xoff(int curve, size_t *len)54{55switch (curve) {56case BR_EC_secp256r1:57return br_ec_p256_m15.xoff(curve, len);58case BR_EC_curve25519:59return br_ec_c25519_m15.xoff(curve, len);60default:61return br_ec_prime_i15.xoff(curve, len);62}63}6465static uint32_t66api_mul(unsigned char *G, size_t Glen,67const unsigned char *kb, size_t kblen, int curve)68{69switch (curve) {70case BR_EC_secp256r1:71return br_ec_p256_m15.mul(G, Glen, kb, kblen, curve);72case BR_EC_curve25519:73return br_ec_c25519_m15.mul(G, Glen, kb, kblen, curve);74default:75return br_ec_prime_i15.mul(G, Glen, kb, kblen, curve);76}77}7879static size_t80api_mulgen(unsigned char *R,81const unsigned char *x, size_t xlen, int curve)82{83switch (curve) {84case BR_EC_secp256r1:85return br_ec_p256_m15.mulgen(R, x, xlen, curve);86case BR_EC_curve25519:87return br_ec_c25519_m15.mulgen(R, x, xlen, curve);88default:89return br_ec_prime_i15.mulgen(R, x, xlen, curve);90}91}9293static uint32_t94api_muladd(unsigned char *A, const unsigned char *B, size_t len,95const unsigned char *x, size_t xlen,96const unsigned char *y, size_t ylen, int curve)97{98switch (curve) {99case BR_EC_secp256r1:100return br_ec_p256_m15.muladd(A, B, len,101x, xlen, y, ylen, curve);102case BR_EC_curve25519:103return br_ec_c25519_m15.muladd(A, B, len,104x, xlen, y, ylen, curve);105default:106return br_ec_prime_i15.muladd(A, B, len,107x, xlen, y, ylen, curve);108}109}110111/* see bearssl_ec.h */112const br_ec_impl br_ec_all_m15 = {113(uint32_t)0x23800000,114&api_generator,115&api_order,116&api_xoff,117&api_mul,118&api_mulgen,119&api_muladd120};121122123