2022-02-25 08:57:19 +01:00
|
|
|
/**
|
|
|
|
* \file pkwrite.h
|
|
|
|
*
|
|
|
|
* \brief Internal defines shared by the PK write module
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright The Mbed TLS Contributors
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MBEDTLS_PK_WRITE_H
|
|
|
|
#define MBEDTLS_PK_WRITE_H
|
|
|
|
|
|
|
|
#include "mbedtls/build_info.h"
|
|
|
|
|
|
|
|
#include "mbedtls/pk.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Max sizes of key per types. Shown as tag + len (+ content).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_RSA_C)
|
|
|
|
/*
|
|
|
|
* RSA public keys:
|
|
|
|
* SubjectPublicKeyInfo ::= SEQUENCE { 1 + 3
|
|
|
|
* algorithm AlgorithmIdentifier, 1 + 1 (sequence)
|
|
|
|
* + 1 + 1 + 9 (rsa oid)
|
|
|
|
* + 1 + 1 (params null)
|
|
|
|
* subjectPublicKey BIT STRING } 1 + 3 + (1 + below)
|
|
|
|
* RSAPublicKey ::= SEQUENCE { 1 + 3
|
|
|
|
* modulus INTEGER, -- n 1 + 3 + MPI_MAX + 1
|
|
|
|
* publicExponent INTEGER -- e 1 + 3 + MPI_MAX + 1
|
|
|
|
* }
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_PK_RSA_PUB_DER_MAX_BYTES (38 + 2 * MBEDTLS_MPI_MAX_SIZE)
|
2022-02-25 08:57:19 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* RSA private keys:
|
|
|
|
* RSAPrivateKey ::= SEQUENCE { 1 + 3
|
|
|
|
* version Version, 1 + 1 + 1
|
|
|
|
* modulus INTEGER, 1 + 3 + MPI_MAX + 1
|
|
|
|
* publicExponent INTEGER, 1 + 3 + MPI_MAX + 1
|
|
|
|
* privateExponent INTEGER, 1 + 3 + MPI_MAX + 1
|
|
|
|
* prime1 INTEGER, 1 + 3 + MPI_MAX / 2 + 1
|
|
|
|
* prime2 INTEGER, 1 + 3 + MPI_MAX / 2 + 1
|
|
|
|
* exponent1 INTEGER, 1 + 3 + MPI_MAX / 2 + 1
|
|
|
|
* exponent2 INTEGER, 1 + 3 + MPI_MAX / 2 + 1
|
|
|
|
* coefficient INTEGER, 1 + 3 + MPI_MAX / 2 + 1
|
|
|
|
* otherPrimeInfos OtherPrimeInfos OPTIONAL 0 (not supported)
|
|
|
|
* }
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_MPI_MAX_SIZE_2 (MBEDTLS_MPI_MAX_SIZE / 2 + \
|
|
|
|
MBEDTLS_MPI_MAX_SIZE % 2)
|
|
|
|
#define MBEDTLS_PK_RSA_PRV_DER_MAX_BYTES (47 + 3 * MBEDTLS_MPI_MAX_SIZE \
|
|
|
|
+ 5 * MBEDTLS_MPI_MAX_SIZE_2)
|
2022-02-25 08:57:19 +01:00
|
|
|
|
|
|
|
#else /* MBEDTLS_RSA_C */
|
|
|
|
|
2022-03-01 10:03:21 +01:00
|
|
|
#define MBEDTLS_PK_RSA_PUB_DER_MAX_BYTES 0
|
|
|
|
#define MBEDTLS_PK_RSA_PRV_DER_MAX_BYTES 0
|
2022-02-25 08:57:19 +01:00
|
|
|
|
|
|
|
#endif /* MBEDTLS_RSA_C */
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_ECP_C)
|
|
|
|
/*
|
|
|
|
* EC public keys:
|
|
|
|
* SubjectPublicKeyInfo ::= SEQUENCE { 1 + 2
|
|
|
|
* algorithm AlgorithmIdentifier, 1 + 1 (sequence)
|
|
|
|
* + 1 + 1 + 7 (ec oid)
|
|
|
|
* + 1 + 1 + 9 (namedCurve oid)
|
|
|
|
* subjectPublicKey BIT STRING 1 + 2 + 1 [1]
|
|
|
|
* + 1 (point format) [1]
|
|
|
|
* + 2 * ECP_MAX (coords) [1]
|
|
|
|
* }
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_PK_ECP_PUB_DER_MAX_BYTES (30 + 2 * MBEDTLS_ECP_MAX_BYTES)
|
2022-02-25 08:57:19 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* EC private keys:
|
|
|
|
* ECPrivateKey ::= SEQUENCE { 1 + 2
|
|
|
|
* version INTEGER , 1 + 1 + 1
|
|
|
|
* privateKey OCTET STRING, 1 + 1 + ECP_MAX
|
|
|
|
* parameters [0] ECParameters OPTIONAL, 1 + 1 + (1 + 1 + 9)
|
|
|
|
* publicKey [1] BIT STRING OPTIONAL 1 + 2 + [1] above
|
|
|
|
* }
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_PK_ECP_PRV_DER_MAX_BYTES (29 + 3 * MBEDTLS_ECP_MAX_BYTES)
|
2022-02-25 08:57:19 +01:00
|
|
|
|
|
|
|
#else /* MBEDTLS_ECP_C */
|
|
|
|
|
2022-03-01 10:03:21 +01:00
|
|
|
#define MBEDTLS_PK_ECP_PUB_DER_MAX_BYTES 0
|
|
|
|
#define MBEDTLS_PK_ECP_PRV_DER_MAX_BYTES 0
|
2022-02-25 08:57:19 +01:00
|
|
|
|
|
|
|
#endif /* MBEDTLS_ECP_C */
|
|
|
|
|
2023-04-19 14:08:14 +02:00
|
|
|
#if defined(MBEDTLS_ECP_LIGHT)
|
|
|
|
#include "mbedtls/ecp.h"
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) || defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
|
|
|
|
#define MBEDTLS_PK_HAVE_RFC8410_CURVES
|
|
|
|
|
|
|
|
static inline int mbedtls_pk_is_rfc8410_curve(mbedtls_ecp_group_id id)
|
|
|
|
{
|
|
|
|
#if defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED)
|
|
|
|
if (id == MBEDTLS_ECP_DP_CURVE25519) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(MBEDTLS_ECP_DP_CURVE448_ENABLED)
|
|
|
|
if (id == MBEDTLS_ECP_DP_CURVE448) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* MBEDTLS_ECP_DP_CURVE25519_ENABLED || MBEDTLS_ECP_DP_CURVE448_ENABLED */
|
|
|
|
#endif /* MBEDTLS_ECP_LIGHT */
|
|
|
|
|
2022-02-25 08:57:19 +01:00
|
|
|
#endif /* MBEDTLS_PK_WRITE_H */
|