aboutsummaryrefslogtreecommitdiff
path: root/openssl/crypto/rsa/rsa_x931.c
diff options
context:
space:
mode:
Diffstat (limited to 'openssl/crypto/rsa/rsa_x931.c')
-rw-r--r--openssl/crypto/rsa/rsa_x931.c198
1 files changed, 94 insertions, 104 deletions
diff --git a/openssl/crypto/rsa/rsa_x931.c b/openssl/crypto/rsa/rsa_x931.c
index 21548e37e..725ead049 100644
--- a/openssl/crypto/rsa/rsa_x931.c
+++ b/openssl/crypto/rsa/rsa_x931.c
@@ -1,6 +1,7 @@
/* rsa_x931.c */
-/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
- * project 2005.
+/*
+ * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
+ * 2005.
*/
/* ====================================================================
* Copyright (c) 2005 The OpenSSL Project. All rights reserved.
@@ -10,7 +11,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -64,114 +65,103 @@
#include <openssl/objects.h>
int RSA_padding_add_X931(unsigned char *to, int tlen,
- const unsigned char *from, int flen)
- {
- int j;
- unsigned char *p;
-
- /* Absolute minimum amount of padding is 1 header nibble, 1 padding
- * nibble and 2 trailer bytes: but 1 hash if is already in 'from'.
- */
-
- j = tlen - flen - 2;
-
- if (j < 0)
- {
- RSAerr(RSA_F_RSA_PADDING_ADD_X931,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
- return -1;
- }
-
- p=(unsigned char *)to;
-
- /* If no padding start and end nibbles are in one byte */
- if (j == 0)
- *p++ = 0x6A;
- else
- {
- *p++ = 0x6B;
- if (j > 1)
- {
- memset(p, 0xBB, j - 1);
- p += j - 1;
- }
- *p++ = 0xBA;
- }
- memcpy(p,from,(unsigned int)flen);
- p += flen;
- *p = 0xCC;
- return(1);
- }
+ const unsigned char *from, int flen)
+{
+ int j;
+ unsigned char *p;
+
+ /*
+ * Absolute minimum amount of padding is 1 header nibble, 1 padding
+ * nibble and 2 trailer bytes: but 1 hash if is already in 'from'.
+ */
+
+ j = tlen - flen - 2;
+
+ if (j < 0) {
+ RSAerr(RSA_F_RSA_PADDING_ADD_X931, RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE);
+ return -1;
+ }
+
+ p = (unsigned char *)to;
+
+ /* If no padding start and end nibbles are in one byte */
+ if (j == 0)
+ *p++ = 0x6A;
+ else {
+ *p++ = 0x6B;
+ if (j > 1) {
+ memset(p, 0xBB, j - 1);
+ p += j - 1;
+ }
+ *p++ = 0xBA;
+ }
+ memcpy(p, from, (unsigned int)flen);
+ p += flen;
+ *p = 0xCC;
+ return (1);
+}
int RSA_padding_check_X931(unsigned char *to, int tlen,
- const unsigned char *from, int flen, int num)
- {
- int i = 0,j;
- const unsigned char *p;
-
- p=from;
- if ((num != flen) || ((*p != 0x6A) && (*p != 0x6B)))
- {
- RSAerr(RSA_F_RSA_PADDING_CHECK_X931,RSA_R_INVALID_HEADER);
- return -1;
- }
-
- if (*p++ == 0x6B)
- {
- j=flen-3;
- for (i = 0; i < j; i++)
- {
- unsigned char c = *p++;
- if (c == 0xBA)
- break;
- if (c != 0xBB)
- {
- RSAerr(RSA_F_RSA_PADDING_CHECK_X931,
- RSA_R_INVALID_PADDING);
- return -1;
- }
- }
-
- j -= i;
-
- if (i == 0)
- {
- RSAerr(RSA_F_RSA_PADDING_CHECK_X931, RSA_R_INVALID_PADDING);
- return -1;
- }
-
- }
- else j = flen - 2;
-
- if (p[j] != 0xCC)
- {
- RSAerr(RSA_F_RSA_PADDING_CHECK_X931, RSA_R_INVALID_TRAILER);
- return -1;
- }
-
- memcpy(to,p,(unsigned int)j);
-
- return(j);
- }
+ const unsigned char *from, int flen, int num)
+{
+ int i = 0, j;
+ const unsigned char *p;
+
+ p = from;
+ if ((num != flen) || ((*p != 0x6A) && (*p != 0x6B))) {
+ RSAerr(RSA_F_RSA_PADDING_CHECK_X931, RSA_R_INVALID_HEADER);
+ return -1;
+ }
+
+ if (*p++ == 0x6B) {
+ j = flen - 3;
+ for (i = 0; i < j; i++) {
+ unsigned char c = *p++;
+ if (c == 0xBA)
+ break;
+ if (c != 0xBB) {
+ RSAerr(RSA_F_RSA_PADDING_CHECK_X931, RSA_R_INVALID_PADDING);
+ return -1;
+ }
+ }
+
+ j -= i;
+
+ if (i == 0) {
+ RSAerr(RSA_F_RSA_PADDING_CHECK_X931, RSA_R_INVALID_PADDING);
+ return -1;
+ }
+
+ } else
+ j = flen - 2;
+
+ if (p[j] != 0xCC) {
+ RSAerr(RSA_F_RSA_PADDING_CHECK_X931, RSA_R_INVALID_TRAILER);
+ return -1;
+ }
+
+ memcpy(to, p, (unsigned int)j);
+
+ return (j);
+}
/* Translate between X931 hash ids and NIDs */
int RSA_X931_hash_id(int nid)
- {
- switch (nid)
- {
- case NID_sha1:
- return 0x33;
+{
+ switch (nid) {
+ case NID_sha1:
+ return 0x33;
- case NID_sha256:
- return 0x34;
+ case NID_sha256:
+ return 0x34;
- case NID_sha384:
- return 0x36;
+ case NID_sha384:
+ return 0x36;
- case NID_sha512:
- return 0x35;
-
- }
- return -1;
- }
+ case NID_sha512:
+ return 0x35;
+ }
+ return -1;
+}