mpal.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /***************************************************************************
  2. Copyright (C) Mindtree Consulting Ltd.
  3. This module is a confidential and proprietary property of Mindtree and
  4. a possession or use of this module requires written permission of Mindtree.
  5. ***************************************************************************/
  6. /**
  7. * \file mpal.h
  8. * Multi-Precision Arithmetic Library(MPAL) interface.
  9. *
  10. * \date 2007-08-20
  11. */
  12. #ifndef _MPAL_H_
  13. #define _MPAL_H_
  14. /* ========================= Include File Section ========================= */
  15. #include "btypes.h"
  16. /* ====================== Macro Declaration Section ======================= */
  17. #ifdef ENABLE_LE_ECDH
  18. /* #define USE_ARM_ASM */
  19. #ifdef USE_32BIT_PROC
  20. #define MPAL_MAX_LEN 16
  21. #define MPAL_BASE 32
  22. #define MPAL_BASE_MASK 0xFFFFFFFF
  23. #else /* USE_32BIT_PROC */
  24. #define MPAL_MAX_LEN 32
  25. #define MPAL_BASE 16
  26. #define MPAL_BASE_MASK 0xFFFF
  27. #endif /* USE_32BIT_PROC */
  28. #define PRIME_BITS 256
  29. #define DHKEY_LEN (PRIME_BITS/8) /* Number of bytes of key as per ECDH procedure */
  30. #define MPAL_PRIME_LEN (PRIME_BITS/MPAL_BASE)
  31. #define mpal_set_number(A, len_A, fill) ecdh_memset((A), (fill), (MPAL_BASE/8) * (len_A));
  32. /* Unsafe, fix this - or use proper Notation. Also depending on sizeof
  33. * (DIGIT ) multiplier*/
  34. #define MPAL_MACRO_DEF u16 macro_len_A
  35. /* Call MPAL_MACRO_DEF in initialization section, before calling this macro */
  36. #define mpal_trim(A,len,out_len) \
  37. macro_len_A = (u16)(len); \
  38. while(macro_len_A && A[--macro_len_A]==0); \
  39. (out_len) = (u16)(macro_len_A+1); \
  40. void convert_to_lsb(u8* bytes, u8 len);
  41. #define convert_to_msb(b, l) convert_to_lsb((b), (l))
  42. /* ==================== Data Types Declaration Section ==================== */
  43. #ifdef USE_32BIT_PROC
  44. typedef s64 SIGNED_BIG_DIGIT;
  45. typedef u64 UNSIGNED_BIG_DIGIT;
  46. typedef u32 DIGIT_S;
  47. #else /* USE_32BIT_PROC */
  48. typedef s32 SIGNED_BIG_DIGIT;
  49. typedef u32 UNSIGNED_BIG_DIGIT;
  50. typedef u16 DIGIT_S;
  51. #endif /* USE_32BIT_PROC */
  52. /* ===================== Variable Declaration Section ===================== */
  53. extern const DIGIT_S PRIME[MPAL_PRIME_LEN];
  54. extern const DIGIT_S curve_a[MPAL_PRIME_LEN];
  55. extern const DIGIT_S curve_b[MPAL_PRIME_LEN];
  56. /* ============================= API Section ============================== */
  57. void mpal_add_u8(INOUT u8* A, u16 len_A, const u8* B, u16 len_B);
  58. void mpal_add(INOUT DIGIT_S* A, const DIGIT_S* B);
  59. void mpal_sub(INOUT DIGIT_S* A, const DIGIT_S* B);
  60. void mpal_mult(const DIGIT_S* A, const DIGIT_S* B, OUT DIGIT_S* C);
  61. s8 mpal_compare(const DIGIT_S* A, const DIGIT_S* B);
  62. u16 mpal_right_shift(INOUT DIGIT_S* A,u16 len_A);
  63. void mpal_mod_by_sub(INOUT DIGIT_S* A);
  64. void mpal_div_by_2(INOUT DIGIT_S* A, INOUT DIGIT_S* B);
  65. void mpal_mult_by_2(INOUT DIGIT_S* A, INOUT DIGIT_S* B);
  66. #endif /* ENABLE_LE_ECDH */
  67. #endif /* _MPAL_H_ */