rsa_none.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright 1995-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. * RSA low level APIs are deprecated for public use, but still ok for
  11. * internal use.
  12. */
  13. #include "internal/deprecated.h"
  14. #include "internal/cryptlib.h"
  15. #include <openssl/bn.h>
  16. #include <openssl/rsa.h>
  17. int RSA_padding_add_none(unsigned char *to, int tlen,
  18. const unsigned char *from, int flen)
  19. {
  20. if (flen > tlen) {
  21. ERR_raise(ERR_LIB_RSA, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
  22. return 0;
  23. }
  24. if (flen < tlen) {
  25. ERR_raise(ERR_LIB_RSA, RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE);
  26. return 0;
  27. }
  28. memcpy(to, from, (unsigned int)flen);
  29. return 1;
  30. }
  31. int RSA_padding_check_none(unsigned char *to, int tlen,
  32. const unsigned char *from, int flen, int num)
  33. {
  34. if (flen > tlen) {
  35. ERR_raise(ERR_LIB_RSA, RSA_R_DATA_TOO_LARGE);
  36. return -1;
  37. }
  38. memset(to, 0, tlen - flen);
  39. memcpy(to + tlen - flen, from, flen);
  40. return tlen;
  41. }