rsa_depr.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2002-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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. /*
  14. * RSA low level APIs are deprecated for public use, but still ok for
  15. * internal use.
  16. */
  17. #include "internal/deprecated.h"
  18. #include <openssl/opensslconf.h>
  19. #include <stdio.h>
  20. #include <time.h>
  21. #include "internal/cryptlib.h"
  22. #include <openssl/bn.h>
  23. #include <openssl/rsa.h>
  24. RSA *RSA_generate_key(int bits, unsigned long e_value,
  25. void (*callback) (int, int, void *), void *cb_arg)
  26. {
  27. int i;
  28. BN_GENCB *cb = BN_GENCB_new();
  29. RSA *rsa = RSA_new();
  30. BIGNUM *e = BN_new();
  31. if (cb == NULL || rsa == NULL || e == NULL)
  32. goto err;
  33. /*
  34. * The problem is when building with 8, 16, or 32 BN_ULONG, unsigned long
  35. * can be larger
  36. */
  37. for (i = 0; i < (int)sizeof(unsigned long) * 8; i++) {
  38. if (e_value & (1UL << i))
  39. if (BN_set_bit(e, i) == 0)
  40. goto err;
  41. }
  42. BN_GENCB_set_old(cb, callback, cb_arg);
  43. if (RSA_generate_key_ex(rsa, bits, e, cb)) {
  44. BN_free(e);
  45. BN_GENCB_free(cb);
  46. return rsa;
  47. }
  48. err:
  49. BN_free(e);
  50. RSA_free(rsa);
  51. BN_GENCB_free(cb);
  52. return 0;
  53. }