• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "bt_types.h"
27 
28 #define DWORD_BITS 32
29 #define DWORD_BYTES 4
30 #define DWORD_BITS_SHIFT 5
31 
32 #define KEY_LENGTH_DWORDS_P192 6
33 #define KEY_LENGTH_DWORDS_P256 8
34 /* Arithmetic Operations */
35 
36 int multiprecision_compare(uint32_t* a, uint32_t* b, uint32_t keyLength);
37 int multiprecision_iszero(uint32_t* a, uint32_t keyLength);
38 void multiprecision_init(uint32_t* c, uint32_t keyLength);
39 void multiprecision_copy(uint32_t* c, uint32_t* a, uint32_t keyLength);
40 uint32_t multiprecision_dword_bits(uint32_t a);
41 uint32_t multiprecision_most_signdwords(uint32_t* a, uint32_t keyLength);
42 uint32_t multiprecision_most_signbits(uint32_t* a, uint32_t keyLength);
43 void multiprecision_inv_mod(uint32_t* aminus, uint32_t* a, uint32_t keyLength);
44 uint32_t multiprecision_add(uint32_t* c, uint32_t* a, uint32_t* b,
45                             uint32_t keyLength);  // c=a+b
46 void multiprecision_add_mod(uint32_t* c, uint32_t* a, uint32_t* b,
47                             uint32_t keyLength);
48 uint32_t multiprecision_sub(uint32_t* c, uint32_t* a, uint32_t* b,
49                             uint32_t keyLength);  // c=a-b
50 void multiprecision_sub_mod(uint32_t* c, uint32_t* a, uint32_t* b,
51                             uint32_t keyLength);
52 void multiprecision_rshift(uint32_t* c, uint32_t* a,
53                            uint32_t keyLength);  // c=a>>1, return carrier
54 void multiprecision_lshift_mod(uint32_t* c, uint32_t* a,
55                                uint32_t keyLength);  // c=a<<b, return carrier
56 uint32_t multiprecision_lshift(uint32_t* c, uint32_t* a,
57                                uint32_t keyLength);  // c=a<<b, return carrier
58 void multiprecision_mult(uint32_t* c, uint32_t* a, uint32_t* b,
59                          uint32_t keyLength);  // c=a*b
60 void multiprecision_mersenns_mult_mod(uint32_t* c, uint32_t* a, uint32_t* b,
61                                       uint32_t keyLength);
62 void multiprecision_mersenns_squa_mod(uint32_t* c, uint32_t* a,
63                                       uint32_t keyLength);
64 uint32_t multiprecision_lshift(uint32_t* c, uint32_t* a, uint32_t keyLength);
65 void multiprecision_mult(uint32_t* c, uint32_t* a, uint32_t* b,
66                          uint32_t keyLength);
67 void multiprecision_fast_mod(uint32_t* c, uint32_t* a);
68 void multiprecision_fast_mod_P256(uint32_t* c, uint32_t* a);
69