RSA_padding_add_PKCS1_type_1.pod 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. =pod
  2. =head1 NAME
  3. RSA_padding_add_PKCS1_type_1, RSA_padding_check_PKCS1_type_1,
  4. RSA_padding_add_PKCS1_type_2, RSA_padding_check_PKCS1_type_2,
  5. RSA_padding_add_PKCS1_OAEP, RSA_padding_check_PKCS1_OAEP,
  6. RSA_padding_add_PKCS1_OAEP_mgf1, RSA_padding_check_PKCS1_OAEP_mgf1,
  7. RSA_padding_add_SSLv23, RSA_padding_check_SSLv23,
  8. RSA_padding_add_none, RSA_padding_check_none - asymmetric encryption
  9. padding
  10. =head1 SYNOPSIS
  11. #include <openssl/rsa.h>
  12. int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen,
  13. const unsigned char *f, int fl);
  14. int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,
  15. const unsigned char *f, int fl, int rsa_len);
  16. int RSA_padding_add_PKCS1_type_2(unsigned char *to, int tlen,
  17. const unsigned char *f, int fl);
  18. int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,
  19. const unsigned char *f, int fl, int rsa_len);
  20. int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
  21. const unsigned char *f, int fl,
  22. const unsigned char *p, int pl);
  23. int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
  24. const unsigned char *f, int fl, int rsa_len,
  25. const unsigned char *p, int pl);
  26. int RSA_padding_add_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
  27. const unsigned char *f, int fl,
  28. const unsigned char *p, int pl,
  29. const EVP_MD *md, const EVP_MD *mgf1md);
  30. int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,
  31. const unsigned char *f, int fl, int rsa_len,
  32. const unsigned char *p, int pl,
  33. const EVP_MD *md, const EVP_MD *mgf1md);
  34. int RSA_padding_add_SSLv23(unsigned char *to, int tlen,
  35. const unsigned char *f, int fl);
  36. int RSA_padding_check_SSLv23(unsigned char *to, int tlen,
  37. const unsigned char *f, int fl, int rsa_len);
  38. int RSA_padding_add_none(unsigned char *to, int tlen,
  39. const unsigned char *f, int fl);
  40. int RSA_padding_check_none(unsigned char *to, int tlen,
  41. const unsigned char *f, int fl, int rsa_len);
  42. =head1 DESCRIPTION
  43. The RSA_padding_xxx_xxx() functions are called from the RSA encrypt,
  44. decrypt, sign and verify functions. Normally they should not be called
  45. from application programs.
  46. However, they can also be called directly to implement padding for other
  47. asymmetric ciphers. RSA_padding_add_PKCS1_OAEP() and
  48. RSA_padding_check_PKCS1_OAEP() may be used in an application combined
  49. with B<RSA_NO_PADDING> in order to implement OAEP with an encoding
  50. parameter.
  51. RSA_padding_add_xxx() encodes B<fl> bytes from B<f> so as to fit into
  52. B<tlen> bytes and stores the result at B<to>. An error occurs if B<fl>
  53. does not meet the size requirements of the encoding method.
  54. The following encoding methods are implemented:
  55. =over 4
  56. =item PKCS1_type_1
  57. PKCS #1 v2.0 EMSA-PKCS1-v1_5 (PKCS #1 v1.5 block type 1); used for signatures
  58. =item PKCS1_type_2
  59. PKCS #1 v2.0 EME-PKCS1-v1_5 (PKCS #1 v1.5 block type 2)
  60. =item PKCS1_OAEP
  61. PKCS #1 v2.0 EME-OAEP
  62. =item SSLv23
  63. PKCS #1 EME-PKCS1-v1_5 with SSL-specific modification
  64. =item none
  65. simply copy the data
  66. =back
  67. The random number generator must be seeded prior to calling
  68. RSA_padding_add_xxx().
  69. If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
  70. external circumstances (see L<RAND(7)>), the operation will fail.
  71. RSA_padding_check_xxx() verifies that the B<fl> bytes at B<f> contain
  72. a valid encoding for a B<rsa_len> byte RSA key in the respective
  73. encoding method and stores the recovered data of at most B<tlen> bytes
  74. (for B<RSA_NO_PADDING>: of size B<tlen>)
  75. at B<to>.
  76. For RSA_padding_xxx_OAEP(), B<p> points to the encoding parameter
  77. of length B<pl>. B<p> may be B<NULL> if B<pl> is 0.
  78. For RSA_padding_xxx_OAEP_mgf1(), B<md> points to the md hash,
  79. if B<md> is B<NULL> that means md=sha1, and B<mgf1md> points to
  80. the mgf1 hash, if B<mgf1md> is B<NULL> that means mgf1md=md.
  81. =head1 RETURN VALUES
  82. The RSA_padding_add_xxx() functions return 1 on success, 0 on error.
  83. The RSA_padding_check_xxx() functions return the length of the
  84. recovered data, -1 on error. Error codes can be obtained by calling
  85. L<ERR_get_error(3)>.
  86. =head1 WARNINGS
  87. The result of RSA_padding_check_PKCS1_type_2() is a very sensitive
  88. information which can potentially be used to mount a Bleichenbacher
  89. padding oracle attack. This is an inherent weakness in the PKCS #1
  90. v1.5 padding design. Prefer PKCS1_OAEP padding. If that is not
  91. possible, the result of RSA_padding_check_PKCS1_type_2() should be
  92. checked in constant time if it matches the expected length of the
  93. plaintext and additionally some application specific consistency
  94. checks on the plaintext need to be performed in constant time.
  95. If the plaintext is rejected it must be kept secret which of the
  96. checks caused the application to reject the message.
  97. Do not remove the zero-padding from the decrypted raw RSA data
  98. which was computed by RSA_private_decrypt() with B<RSA_NO_PADDING>,
  99. as this would create a small timing side channel which could be
  100. used to mount a Bleichenbacher attack against any padding mode
  101. including PKCS1_OAEP.
  102. =head1 SEE ALSO
  103. L<RSA_public_encrypt(3)>,
  104. L<RSA_private_decrypt(3)>,
  105. L<RSA_sign(3)>, L<RSA_verify(3)>,
  106. L<RAND(7)>
  107. =head1 COPYRIGHT
  108. Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
  109. Licensed under the Apache License 2.0 (the "License"). You may not use
  110. this file except in compliance with the License. You can obtain a copy
  111. in the file LICENSE in the source distribution or at
  112. L<https://www.openssl.org/source/license.html>.
  113. =cut