openssl/crypto/asn1/t_pkey.c
Dr. Matthias St. Pierre 0c994d54af Reorganize private crypto header files
Currently, there are two different directories which contain internal
header files of libcrypto which are meant to be shared internally:

While header files in 'include/internal' are intended to be shared
between libcrypto and libssl, the files in 'crypto/include/internal'
are intended to be shared inside libcrypto only.

To make things complicated, the include search path is set up in such
a way that the directive #include "internal/file.h" could refer to
a file in either of these two directoroes. This makes it necessary
in some cases to add a '_int.h' suffix to some files to resolve this
ambiguity:

  #include "internal/file.h"      # located in 'include/internal'
  #include "internal/file_int.h"  # located in 'crypto/include/internal'

This commit moves the private crypto headers from

  'crypto/include/internal'  to  'include/crypto'

As a result, the include directives become unambiguous

  #include "internal/file.h"       # located in 'include/internal'
  #include "crypto/file.h"         # located in 'include/crypto'

hence the superfluous '_int.h' suffixes can be stripped.

The files 'store_int.h' and 'store.h' need to be treated specially;
they are joined into a single file.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9681)
2019-09-27 23:57:58 +02:00

93 lines
2.5 KiB
C

/*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/objects.h>
#include <openssl/buffer.h>
#include "crypto/bn.h"
/* Number of octets per line */
#define ASN1_BUF_PRINT_WIDTH 15
/* Maximum indent */
#define ASN1_PRINT_MAX_INDENT 128
int ASN1_buf_print(BIO *bp, const unsigned char *buf, size_t buflen, int indent)
{
size_t i;
for (i = 0; i < buflen; i++) {
if ((i % ASN1_BUF_PRINT_WIDTH) == 0) {
if (i > 0 && BIO_puts(bp, "\n") <= 0)
return 0;
if (!BIO_indent(bp, indent, ASN1_PRINT_MAX_INDENT))
return 0;
}
/*
* Use colon separators for each octet for compatibility as
* this function is used to print out key components.
*/
if (BIO_printf(bp, "%02x%s", buf[i],
(i == buflen - 1) ? "" : ":") <= 0)
return 0;
}
if (BIO_write(bp, "\n", 1) <= 0)
return 0;
return 1;
}
int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
unsigned char *ign, int indent)
{
int n, rv = 0;
const char *neg;
unsigned char *buf = NULL, *tmp = NULL;
int buflen;
if (num == NULL)
return 1;
neg = BN_is_negative(num) ? "-" : "";
if (!BIO_indent(bp, indent, ASN1_PRINT_MAX_INDENT))
return 0;
if (BN_is_zero(num)) {
if (BIO_printf(bp, "%s 0\n", number) <= 0)
return 0;
return 1;
}
if (BN_num_bytes(num) <= BN_BYTES) {
if (BIO_printf(bp, "%s %s%lu (%s0x%lx)\n", number, neg,
(unsigned long)bn_get_words(num)[0], neg,
(unsigned long)bn_get_words(num)[0]) <= 0)
return 0;
return 1;
}
buflen = BN_num_bytes(num) + 1;
buf = tmp = OPENSSL_malloc(buflen);
if (buf == NULL)
goto err;
buf[0] = 0;
if (BIO_printf(bp, "%s%s\n", number,
(neg[0] == '-') ? " (Negative)" : "") <= 0)
goto err;
n = BN_bn2bin(num, buf + 1);
if (buf[1] & 0x80)
n++;
else
tmp++;
if (ASN1_buf_print(bp, tmp, n, indent + 4) == 0)
goto err;
rv = 1;
err:
OPENSSL_clear_free(buf, buflen);
return rv;
}