1 /****************************************************************************** 2 * 3 * Copyright 2006-2015 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 /******************************************************************************* 20 * 21 * This file contains simple pairing algorithms 22 * 23 ******************************************************************************/ 24 #pragma once 25 26 #include <cstdint> 27 28 namespace bluetooth { 29 namespace security { 30 namespace ecc { 31 32 #define KEY_LENGTH_DWORDS_P256 8 33 /* Arithmetic Operations*/ 34 int multiprecision_compare(const uint32_t* a, const uint32_t* b); 35 int multiprecision_iszero(const uint32_t* a); 36 void multiprecision_init(uint32_t* c); 37 void multiprecision_copy(uint32_t* c, const uint32_t* a); 38 uint32_t multiprecision_dword_bits(uint32_t a); 39 uint32_t multiprecision_most_signdwords(const uint32_t* a); 40 uint32_t multiprecision_most_signbits(const uint32_t* a); 41 void multiprecision_inv_mod(uint32_t* aminus, uint32_t* a, const uint32_t* modp); 42 uint32_t multiprecision_add(uint32_t* c, const uint32_t* a, const uint32_t* b); // c=a+b 43 void multiprecision_add_mod(uint32_t* c, const uint32_t* a, const uint32_t* b, const uint32_t* modp); 44 uint32_t multiprecision_sub(uint32_t* c, const uint32_t* a, const uint32_t* b); // c=a-b 45 void multiprecision_sub_mod(uint32_t* c, const uint32_t* a, const uint32_t* b, const uint32_t* modp); 46 void multiprecision_rshift(uint32_t* c, const uint32_t* a); // c=a>>1, return carrier 47 void multiprecision_lshift_mod(uint32_t* c, const uint32_t* a, const uint32_t* modp); // c=a<<b, return carrier 48 uint32_t multiprecision_lshift(uint32_t* c, const uint32_t* a); 49 void multiprecision_mult(uint32_t* c, const uint32_t* a, const uint32_t* b); // c=a*b 50 void multiprecision_mersenns_mult_mod(uint32_t* c, const uint32_t* a, const uint32_t* b, const uint32_t* modp); 51 void multiprecision_mersenns_squa_mod(uint32_t* c, const uint32_t* a, const uint32_t* modp); 52 void multiprecision_fast_mod_P256(uint32_t* c, const uint32_t* a, const uint32_t* modp); 53 54 } // namespace ecc 55 } // namespace security 56 } // namespace bluetooth