p_256_multprecision.h 3.2 KB

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