2 * Copyright 2005-2020 The OpenSSL Project Authors. All Rights Reserved.
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
11 * RSA low level APIs are deprecated for public use, but still ok for
14 #include "internal/deprecated.h"
17 #include "internal/cryptlib.h"
18 #include <openssl/bn.h>
19 #include <openssl/rsa.h>
20 #include <openssl/objects.h>
22 int RSA_padding_add_X931(unsigned char *to
, int tlen
,
23 const unsigned char *from
, int flen
)
29 * Absolute minimum amount of padding is 1 header nibble, 1 padding
30 * nibble and 2 trailer bytes: but 1 hash if is already in 'from'.
36 RSAerr(RSA_F_RSA_PADDING_ADD_X931
, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE
);
40 p
= (unsigned char *)to
;
42 /* If no padding start and end nibbles are in one byte */
48 memset(p
, 0xBB, j
- 1);
53 memcpy(p
, from
, (unsigned int)flen
);
59 int RSA_padding_check_X931(unsigned char *to
, int tlen
,
60 const unsigned char *from
, int flen
, int num
)
63 const unsigned char *p
;
66 if ((num
!= flen
) || ((*p
!= 0x6A) && (*p
!= 0x6B))) {
67 RSAerr(RSA_F_RSA_PADDING_CHECK_X931
, RSA_R_INVALID_HEADER
);
73 for (i
= 0; i
< j
; i
++) {
74 unsigned char c
= *p
++;
78 RSAerr(RSA_F_RSA_PADDING_CHECK_X931
, RSA_R_INVALID_PADDING
);
86 RSAerr(RSA_F_RSA_PADDING_CHECK_X931
, RSA_R_INVALID_PADDING
);
95 RSAerr(RSA_F_RSA_PADDING_CHECK_X931
, RSA_R_INVALID_TRAILER
);
99 memcpy(to
, p
, (unsigned int)j
);
104 /* Translate between X931 hash ids and NIDs */
106 int RSA_X931_hash_id(int nid
)