Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
crypto_misc.h
00001 /* 00002 * Copyright (c) 2007, Cameron Rich 00003 * 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * * Redistributions of source code must retain the above copyright notice, 00010 * this list of conditions and the following disclaimer. 00011 * * Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * * Neither the name of the axTLS project nor the names of its contributors 00015 * may be used to endorse or promote products derived from this software 00016 * without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00019 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00020 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00021 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00022 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00023 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00024 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00025 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00026 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00027 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00030 00031 /** 00032 * @file crypto_misc.h 00033 */ 00034 00035 #ifndef HEADER_CRYPTO_MISC_H 00036 #define HEADER_CRYPTO_MISC_H 00037 00038 #ifdef __cplusplus 00039 extern "C" { 00040 #endif 00041 00042 #include "crypto.h " 00043 #include "bigint.h" 00044 #include "config.h" 00045 00046 /************************************************************************** 00047 * X509 declarations 00048 **************************************************************************/ 00049 #define X509_OK 0 00050 #define X509_NOT_OK -1 00051 #define X509_VFY_ERROR_NO_TRUSTED_CERT -2 00052 #define X509_VFY_ERROR_BAD_SIGNATURE -3 00053 #define X509_VFY_ERROR_NOT_YET_VALID -4 00054 #define X509_VFY_ERROR_EXPIRED -5 00055 #define X509_VFY_ERROR_SELF_SIGNED -6 00056 #define X509_VFY_ERROR_INVALID_CHAIN -7 00057 #define X509_VFY_ERROR_UNSUPPORTED_DIGEST -8 00058 #define X509_INVALID_PRIV_KEY -9 00059 00060 /* 00061 * The Distinguished Name 00062 */ 00063 #define X509_NUM_DN_TYPES 3 00064 #define X509_COMMON_NAME 0 00065 #define X509_ORGANIZATION 1 00066 #define X509_ORGANIZATIONAL_UNIT 2 00067 00068 #include <time.h> 00069 00070 struct _x509_ctx 00071 { 00072 char *ca_cert_dn[X509_NUM_DN_TYPES]; 00073 char *cert_dn[X509_NUM_DN_TYPES]; 00074 char **subject_alt_dnsnames; 00075 time_t not_before; 00076 time_t not_after; 00077 uint8_t *signature; 00078 uint16_t sig_len; 00079 uint8_t sig_type; 00080 RSA_CTX *rsa_ctx; 00081 bigint *digest; 00082 struct _x509_ctx *next; 00083 }; 00084 00085 typedef struct _x509_ctx X509_CTX; 00086 typedef struct 00087 { 00088 X509_CTX *cert[CONFIG_X509_MAX_CA_CERTS]; 00089 } CA_CERT_CTX; 00090 #ifdef CONFIG_SSL_CERT_VERIFICATION 00091 00092 #endif 00093 00094 int x509_new(const uint8_t *cert, int *len, X509_CTX **ctx); 00095 void x509_free(X509_CTX *x509_ctx); 00096 int x509_verify(const CA_CERT_CTX *ca_cert_ctx, const X509_CTX *cert); 00097 00098 #ifdef CONFIG_SSL_CERT_VERIFICATION 00099 #endif 00100 #ifdef CONFIG_SSL_FULL_MODE 00101 void x509_print(const X509_CTX *cert, CA_CERT_CTX *ca_cert_ctx); 00102 const char * x509_display_error(int error); 00103 #endif 00104 00105 /************************************************************************** 00106 * ASN1 declarations 00107 **************************************************************************/ 00108 #define ASN1_INTEGER 0x02 00109 #define ASN1_BIT_STRING 0x03 00110 #define ASN1_OCTET_STRING 0x04 00111 #define ASN1_NULL 0x05 00112 #define ASN1_PRINTABLE_STR2 0x0C 00113 #define ASN1_OID 0x06 00114 #define ASN1_PRINTABLE_STR2 0x0C 00115 #define ASN1_PRINTABLE_STR 0x13 00116 #define ASN1_TELETEX_STR 0x14 00117 #define ASN1_IA5_STR 0x16 00118 #define ASN1_UTC_TIME 0x17 00119 #define ASN1_UNICODE_STR 0x1e 00120 #define ASN1_SEQUENCE 0x30 00121 #define ASN1_CONTEXT_DNSNAME 0x82 00122 #define ASN1_SET 0x31 00123 #define ASN1_V3_DATA 0xa3 00124 #define ASN1_IMPLICIT_TAG 0x80 00125 #define ASN1_CONTEXT_DNSNAME 0x82 00126 #define ASN1_EXPLICIT_TAG 0xa0 00127 #define ASN1_V3_DATA 0xa3 00128 00129 #define SIG_TYPE_MD2 0x02 00130 #define SIG_TYPE_MD5 0x04 00131 #define SIG_TYPE_SHA1 0x05 00132 00133 int get_asn1_length(const uint8_t *buf, int *offset); 00134 int asn1_get_private_key(const uint8_t *buf, int len, RSA_CTX **rsa_ctx); 00135 int asn1_next_obj(const uint8_t *buf, int *offset, int obj_type); 00136 int asn1_skip_obj(const uint8_t *buf, int *offset, int obj_type); 00137 int asn1_get_int(const uint8_t *buf, int *offset, uint8_t **object); 00138 int asn1_version(const uint8_t *cert, int *offset, X509_CTX *x509_ctx); 00139 int asn1_validity(const uint8_t *cert, int *offset, X509_CTX *x509_ctx); 00140 int asn1_name(const uint8_t *cert, int *offset, char *dn[]); 00141 int asn1_public_key(const uint8_t *cert, int *offset, X509_CTX *x509_ctx); 00142 #ifdef CONFIG_SSL_CERT_VERIFICATION 00143 int asn1_signature(const uint8_t *cert, int *offset, X509_CTX *x509_ctx); 00144 int asn1_find_subjectaltname(const uint8_t* cert, int offset); 00145 int asn1_compare_dn(char * const dn1[], char * const dn2[]); 00146 #endif /* CONFIG_SSL_CERT_VERIFICATION */ 00147 int asn1_signature_type(const uint8_t *cert, 00148 int *offset, X509_CTX *x509_ctx); 00149 00150 /************************************************************************** 00151 * MISC declarations 00152 **************************************************************************/ 00153 #define SALT_SIZE 8 00154 00155 extern const char * const unsupported_str; 00156 00157 typedef void (*crypt_func)(void *, const uint8_t *, uint8_t *, int); 00158 typedef void (*hmac_func)(const uint8_t *msg, int length, const uint8_t *key, 00159 int key_len, uint8_t *digest); 00160 00161 int get_file(const char *filename, uint8_t **buf); 00162 00163 #if defined(CONFIG_SSL_FULL_MODE) || defined(WIN32) || defined(CONFIG_DEBUG) 00164 EXP_FUNC void STDCALL print_blob(const char *format, const uint8_t *data, int size, ...); 00165 #else 00166 #define print_blob(...) 00167 #endif 00168 00169 EXP_FUNC int STDCALL base64_decode(const char *in, int len, 00170 uint8_t *out, int *outlen); 00171 00172 #ifdef __cplusplus 00173 } 00174 #endif 00175 00176 #endif
Generated on Tue Jul 12 2022 12:28:29 by
