1 /****************************************************************************** 2 * 3 * Copyright (C) 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 using Elliptic Curve Cryptography for private public key 22 * 23 ******************************************************************************/ 24 25 #pragma once 26 27 #include "p_256_multprecision.h" 28 #include "common/bt_target.h" 29 30 typedef unsigned long DWORD; 31 32 typedef struct { 33 DWORD x[KEY_LENGTH_DWORDS_P256]; 34 DWORD y[KEY_LENGTH_DWORDS_P256]; 35 DWORD z[KEY_LENGTH_DWORDS_P256]; 36 } Point; 37 38 typedef struct { 39 // curve's coefficients 40 DWORD a[KEY_LENGTH_DWORDS_P256]; 41 DWORD b[KEY_LENGTH_DWORDS_P256]; 42 43 //whether a is -3 44 int a_minus3; 45 46 // prime modulus 47 DWORD p[KEY_LENGTH_DWORDS_P256]; 48 49 // Omega, p = 2^m -omega 50 DWORD omega[KEY_LENGTH_DWORDS_P256]; 51 52 // base point, a point on E of order r 53 Point G; 54 55 } elliptic_curve_t; 56 57 #if SMP_DYNAMIC_MEMORY == 0 58 extern elliptic_curve_t curve; 59 extern elliptic_curve_t curve_p256; 60 #else 61 extern elliptic_curve_t *curve_ptr; 62 extern elliptic_curve_t *curve_p256_ptr; 63 #define curve (*curve_ptr) 64 #define curve_p256 (*curve_p256_ptr) 65 #endif 66 67 68 void ECC_PointMult_Bin_NAF(Point *q, Point *p, DWORD *n, uint32_t keyLength); 69 70 bool ECC_CheckPointIsInElliCur_P256(Point *p); 71 72 #define ECC_PointMult(q, p, n, keyLength) ECC_PointMult_Bin_NAF(q, p, n, keyLength) 73 74 void p_256_init_curve(UINT32 keyLength); 75