bn_int.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef HEADER_BN_INT_H
  10. # define HEADER_BN_INT_H
  11. # include <openssl/bn.h>
  12. # include <limits.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. BIGNUM *bn_wexpand(BIGNUM *a, int words);
  17. BIGNUM *bn_expand2(BIGNUM *a, int words);
  18. void bn_correct_top(BIGNUM *a);
  19. /*
  20. * Determine the modified width-(w+1) Non-Adjacent Form (wNAF) of 'scalar'.
  21. * This is an array r[] of values that are either zero or odd with an
  22. * absolute value less than 2^w satisfying scalar = \sum_j r[j]*2^j where at
  23. * most one of any w+1 consecutive digits is non-zero with the exception that
  24. * the most significant digit may be only w-1 zeros away from that next
  25. * non-zero digit.
  26. */
  27. signed char *bn_compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len);
  28. int bn_get_top(const BIGNUM *a);
  29. int bn_get_dmax(const BIGNUM *a);
  30. /* Set all words to zero */
  31. void bn_set_all_zero(BIGNUM *a);
  32. /*
  33. * Copy the internal BIGNUM words into out which holds size elements (and size
  34. * must be bigger than top)
  35. */
  36. int bn_copy_words(BN_ULONG *out, const BIGNUM *in, int size);
  37. BN_ULONG *bn_get_words(const BIGNUM *a);
  38. /*
  39. * Set the internal data words in a to point to words which contains size
  40. * elements. The BN_FLG_STATIC_DATA flag is set
  41. */
  42. void bn_set_static_words(BIGNUM *a, BN_ULONG *words, int size);
  43. /*
  44. * Copy words into the BIGNUM |a|, reallocating space as necessary.
  45. * The negative flag of |a| is not modified.
  46. * Returns 1 on success and 0 on failure.
  47. */
  48. /*
  49. * |num_words| is int because bn_expand2 takes an int. This is an internal
  50. * function so we simply trust callers not to pass negative values.
  51. */
  52. int bn_set_words(BIGNUM *a, BN_ULONG *words, int num_words);
  53. #ifdef __cplusplus
  54. }
  55. #endif
  56. #endif