2
0

rsa_none.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright 1995-2017 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. #include "internal/cryptlib.h"
  10. #include <openssl/bn.h>
  11. #include <openssl/rsa.h>
  12. int RSA_padding_add_none(unsigned char *to, int tlen,
  13. const unsigned char *from, int flen)
  14. {
  15. if (flen > tlen) {
  16. RSAerr(RSA_F_RSA_PADDING_ADD_NONE, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
  17. return 0;
  18. }
  19. if (flen < tlen) {
  20. RSAerr(RSA_F_RSA_PADDING_ADD_NONE, RSA_R_DATA_TOO_SMALL_FOR_KEY_SIZE);
  21. return 0;
  22. }
  23. memcpy(to, from, (unsigned int)flen);
  24. return 1;
  25. }
  26. int RSA_padding_check_none(unsigned char *to, int tlen,
  27. const unsigned char *from, int flen, int num)
  28. {
  29. if (flen > tlen) {
  30. RSAerr(RSA_F_RSA_PADDING_CHECK_NONE, RSA_R_DATA_TOO_LARGE);
  31. return -1;
  32. }
  33. memset(to, 0, tlen - flen);
  34. memcpy(to + tlen - flen, from, flen);
  35. return tlen;
  36. }