p_256_multprecision.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. * This file contains simple pairing algorithms
  21. *
  22. ******************************************************************************/
  23. #pragma once
  24. #include "stack/bt_types.h"
  25. /* Type definitions */
  26. typedef unsigned long DWORD;
  27. #define DWORD_BITS 32
  28. #define DWORD_BYTES 4
  29. #define DWORD_BITS_SHIFT 5
  30. #define KEY_LENGTH_DWORDS_P192 6
  31. #define KEY_LENGTH_DWORDS_P256 8
  32. /* Arithmetic Operations */
  33. int multiprecision_compare(DWORD *a, DWORD *b, uint32_t keyLength);
  34. int multiprecision_iszero(DWORD *a, uint32_t keyLength);
  35. void multiprecision_init(DWORD *c, uint32_t keyLength);
  36. void multiprecision_copy(DWORD *c, DWORD *a, uint32_t keyLength);
  37. UINT32 multiprecision_dword_bits (DWORD a);
  38. UINT32 multiprecision_most_signdwords(DWORD *a, uint32_t keyLength);
  39. UINT32 multiprecision_most_signbits(DWORD *a, uint32_t keyLength);
  40. void multiprecision_inv_mod(DWORD *aminus, DWORD *a, uint32_t keyLength);
  41. DWORD multiprecision_add(DWORD *c, DWORD *a, DWORD *b, uint32_t keyLength); // c=a+b
  42. void multiprecision_add_mod(DWORD *c, DWORD *a, DWORD *b, uint32_t keyLength);
  43. DWORD multiprecision_sub(DWORD *c, DWORD *a, DWORD *b, uint32_t keyLength); // c=a-b
  44. void multiprecision_sub_mod(DWORD *c, DWORD *a, DWORD *b, uint32_t keyLength);
  45. void multiprecision_rshift(DWORD *c, DWORD *a, uint32_t keyLength); // c=a>>1, return carrier
  46. void multiprecision_lshift_mod(DWORD *c, DWORD *a, uint32_t keyLength); // c=a<<b, return carrier
  47. DWORD multiprecision_lshift(DWORD *c, DWORD *a, uint32_t keyLength); // c=a<<b, return carrier
  48. void multiprecision_mult(DWORD *c, DWORD *a, DWORD *b, uint32_t keyLength); // c=a*b
  49. void multiprecision_mersenns_mult_mod(DWORD *c, DWORD *a, DWORD *b, uint32_t keyLength);
  50. void multiprecision_mersenns_squa_mod(DWORD *c, DWORD *a, uint32_t keyLength);
  51. DWORD multiprecision_lshift(DWORD *c, DWORD *a, uint32_t keyLength);
  52. void multiprecision_mult(DWORD *c, DWORD *a, DWORD *b, uint32_t keyLength);
  53. void multiprecision_fast_mod(DWORD *c, DWORD *a);
  54. void multiprecision_fast_mod_P256(DWORD *c, DWORD *a);