rsa_depr.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright 2002-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. /*
  10. * NB: This file contains deprecated functions (compatibility wrappers to the
  11. * "new" versions).
  12. */
  13. #include <openssl/opensslconf.h>
  14. #if OPENSSL_API_COMPAT >= 0x00908000L
  15. NON_EMPTY_TRANSLATION_UNIT
  16. #else
  17. # include <stdio.h>
  18. # include <time.h>
  19. # include "internal/cryptlib.h"
  20. # include <openssl/bn.h>
  21. # include <openssl/rsa.h>
  22. RSA *RSA_generate_key(int bits, unsigned long e_value,
  23. void (*callback) (int, int, void *), void *cb_arg)
  24. {
  25. int i;
  26. BN_GENCB *cb = BN_GENCB_new();
  27. RSA *rsa = RSA_new();
  28. BIGNUM *e = BN_new();
  29. if (cb == NULL || rsa == NULL || e == NULL)
  30. goto err;
  31. /*
  32. * The problem is when building with 8, 16, or 32 BN_ULONG, unsigned long
  33. * can be larger
  34. */
  35. for (i = 0; i < (int)sizeof(unsigned long) * 8; i++) {
  36. if (e_value & (1UL << i))
  37. if (BN_set_bit(e, i) == 0)
  38. goto err;
  39. }
  40. BN_GENCB_set_old(cb, callback, cb_arg);
  41. if (RSA_generate_key_ex(rsa, bits, e, cb)) {
  42. BN_free(e);
  43. BN_GENCB_free(cb);
  44. return rsa;
  45. }
  46. err:
  47. BN_free(e);
  48. RSA_free(rsa);
  49. BN_GENCB_free(cb);
  50. return 0;
  51. }
  52. #endif