blob: d9e3e5c8ff3092d8f720d8809762cb60e39dc6bc [file] [log] [blame]
Manuel Pégourié-Gonnard5e94dde2015-05-26 11:57:05 +02001/**
2 * \file ssl_ticket.h
3 *
4 * \brief Internal functions shared by the SSL modules
5 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02006 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02007 * SPDX-License-Identifier: Apache-2.0
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
10 * not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
Manuel Pégourié-Gonnard5e94dde2015-05-26 11:57:05 +020020 *
21 * This file is part of mbed TLS (https://tls.mbed.org)
Manuel Pégourié-Gonnard5e94dde2015-05-26 11:57:05 +020022 */
23#ifndef MBEDTLS_SSL_INTERNAL_H
24#define MBEDTLS_SSL_INTERNAL_H
25
26#include "ssl.h"
27
Manuel Pégourié-Gonnard56273da2015-05-26 12:19:45 +020028#if defined(MBEDTLS_MD5_C)
29#include "md5.h"
30#endif
31
32#if defined(MBEDTLS_SHA1_C)
33#include "sha1.h"
34#endif
35
36#if defined(MBEDTLS_SHA256_C)
37#include "sha256.h"
38#endif
39
40#if defined(MBEDTLS_SHA512_C)
41#include "sha512.h"
42#endif
43
Manuel Pégourié-Gonnardeef142d2015-09-16 10:05:04 +020044#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
Manuel Pégourié-Gonnard76cfd3f2015-09-15 12:10:54 +020045#include "ecjpake.h"
46#endif
47
Manuel Pégourié-Gonnard20af64d2015-07-07 18:33:39 +020048#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && !defined(inline)
Manuel Pégourié-Gonnard065122c2015-05-26 12:31:46 +020049#define inline __inline
Manuel Pégourié-Gonnard20af64d2015-07-07 18:33:39 +020050#endif
Manuel Pégourié-Gonnard065122c2015-05-26 12:31:46 +020051
52/* Determine minimum supported version */
53#define MBEDTLS_SSL_MIN_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3
54
55#if defined(MBEDTLS_SSL_PROTO_SSL3)
56#define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_0
57#else
58#if defined(MBEDTLS_SSL_PROTO_TLS1)
59#define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_1
60#else
61#if defined(MBEDTLS_SSL_PROTO_TLS1_1)
62#define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_2
63#else
64#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
65#define MBEDTLS_SSL_MIN_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_3
66#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
67#endif /* MBEDTLS_SSL_PROTO_TLS1_1 */
68#endif /* MBEDTLS_SSL_PROTO_TLS1 */
69#endif /* MBEDTLS_SSL_PROTO_SSL3 */
70
71/* Determine maximum supported version */
72#define MBEDTLS_SSL_MAX_MAJOR_VERSION MBEDTLS_SSL_MAJOR_VERSION_3
73
74#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
75#define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_3
76#else
77#if defined(MBEDTLS_SSL_PROTO_TLS1_1)
78#define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_2
79#else
80#if defined(MBEDTLS_SSL_PROTO_TLS1)
81#define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_1
82#else
83#if defined(MBEDTLS_SSL_PROTO_SSL3)
84#define MBEDTLS_SSL_MAX_MINOR_VERSION MBEDTLS_SSL_MINOR_VERSION_0
85#endif /* MBEDTLS_SSL_PROTO_SSL3 */
86#endif /* MBEDTLS_SSL_PROTO_TLS1 */
87#endif /* MBEDTLS_SSL_PROTO_TLS1_1 */
88#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
89
90#define MBEDTLS_SSL_INITIAL_HANDSHAKE 0
91#define MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS 1 /* In progress */
92#define MBEDTLS_SSL_RENEGOTIATION_DONE 2 /* Done or aborted */
93#define MBEDTLS_SSL_RENEGOTIATION_PENDING 3 /* Requested (server only) */
94
95/*
96 * DTLS retransmission states, see RFC 6347 4.2.4
97 *
98 * The SENDING state is merged in PREPARING for initial sends,
99 * but is distinct for resends.
100 *
101 * Note: initial state is wrong for server, but is not used anyway.
102 */
103#define MBEDTLS_SSL_RETRANS_PREPARING 0
104#define MBEDTLS_SSL_RETRANS_SENDING 1
105#define MBEDTLS_SSL_RETRANS_WAITING 2
106#define MBEDTLS_SSL_RETRANS_FINISHED 3
107
108/*
109 * Allow extra bytes for record, authentication and encryption overhead:
110 * counter (8) + header (5) + IV(16) + MAC (16-48) + padding (0-256)
111 * and allow for a maximum of 1024 of compression expansion if
112 * enabled.
113 */
114#if defined(MBEDTLS_ZLIB_SUPPORT)
115#define MBEDTLS_SSL_COMPRESSION_ADD 1024
116#else
117#define MBEDTLS_SSL_COMPRESSION_ADD 0
118#endif
119
120#if defined(MBEDTLS_ARC4_C) || defined(MBEDTLS_CIPHER_MODE_CBC)
121/* Ciphersuites using HMAC */
122#if defined(MBEDTLS_SHA512_C)
123#define MBEDTLS_SSL_MAC_ADD 48 /* SHA-384 used for HMAC */
124#elif defined(MBEDTLS_SHA256_C)
125#define MBEDTLS_SSL_MAC_ADD 32 /* SHA-256 used for HMAC */
126#else
127#define MBEDTLS_SSL_MAC_ADD 20 /* SHA-1 used for HMAC */
128#endif
129#else
130/* AEAD ciphersuites: GCM and CCM use a 128 bits tag */
131#define MBEDTLS_SSL_MAC_ADD 16
132#endif
133
134#if defined(MBEDTLS_CIPHER_MODE_CBC)
135#define MBEDTLS_SSL_PADDING_ADD 256
136#else
137#define MBEDTLS_SSL_PADDING_ADD 0
138#endif
139
140#define MBEDTLS_SSL_BUFFER_LEN ( MBEDTLS_SSL_MAX_CONTENT_LEN \
141 + MBEDTLS_SSL_COMPRESSION_ADD \
142 + 29 /* counter + header + IV */ \
143 + MBEDTLS_SSL_MAC_ADD \
144 + MBEDTLS_SSL_PADDING_ADD \
145 )
146
147/*
148 * TLS extension flags (for extensions with outgoing ServerHello content
149 * that need it (e.g. for RENEGOTIATION_INFO the server already knows because
150 * of state of the renegotiation flag, so no indicator is required)
151 */
152#define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT (1 << 0)
153
Manuel Pégourié-Gonnard5e94dde2015-05-26 11:57:05 +0200154#ifdef __cplusplus
155extern "C" {
156#endif
157
Manuel Pégourié-Gonnardcd4fcc62015-05-26 12:11:48 +0200158/*
159 * This structure contains the parameters only needed during handshake.
160 */
161struct mbedtls_ssl_handshake_params
162{
163 /*
164 * Handshake specific crypto variables
165 */
166 int sig_alg; /*!< Hash algorithm for signature */
167 int cert_type; /*!< Requested cert type */
168 int verify_sig_alg; /*!< Signature algorithm for verify */
169#if defined(MBEDTLS_DHM_C)
170 mbedtls_dhm_context dhm_ctx; /*!< DHM key exchange */
171#endif
172#if defined(MBEDTLS_ECDH_C)
173 mbedtls_ecdh_context ecdh_ctx; /*!< ECDH key exchange */
174#endif
Manuel Pégourié-Gonnardeef142d2015-09-16 10:05:04 +0200175#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
Manuel Pégourié-Gonnard76cfd3f2015-09-15 12:10:54 +0200176 mbedtls_ecjpake_context ecjpake_ctx; /*!< EC J-PAKE key exchange */
177#endif
Manuel Pégourié-Gonnardf4721792015-09-15 10:53:51 +0200178#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || \
Manuel Pégourié-Gonnardeef142d2015-09-16 10:05:04 +0200179 defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
Manuel Pégourié-Gonnardcd4fcc62015-05-26 12:11:48 +0200180 const mbedtls_ecp_curve_info **curves; /*!< Supported elliptic curves */
181#endif
182#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
183 unsigned char *psk; /*!< PSK from the callback */
184 size_t psk_len; /*!< Length of PSK from callback */
185#endif
186#if defined(MBEDTLS_X509_CRT_PARSE_C)
187 mbedtls_ssl_key_cert *key_cert; /*!< chosen key/cert pair (server) */
188#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
Manuel Pégourié-Gonnardcdc26ae2015-06-19 12:16:31 +0200189 int sni_authmode; /*!< authmode from SNI callback */
Manuel Pégourié-Gonnardcd4fcc62015-05-26 12:11:48 +0200190 mbedtls_ssl_key_cert *sni_key_cert; /*!< key/cert list from SNI */
191 mbedtls_x509_crt *sni_ca_chain; /*!< trusted CAs from SNI callback */
192 mbedtls_x509_crl *sni_ca_crl; /*!< trusted CAs CRLs from SNI */
193#endif
194#endif /* MBEDTLS_X509_CRT_PARSE_C */
195#if defined(MBEDTLS_SSL_PROTO_DTLS)
196 unsigned int out_msg_seq; /*!< Outgoing handshake sequence number */
197 unsigned int in_msg_seq; /*!< Incoming handshake sequence number */
198
199 unsigned char *verify_cookie; /*!< Cli: HelloVerifyRequest cookie
200 Srv: unused */
201 unsigned char verify_cookie_len; /*!< Cli: cookie length
202 Srv: flag for sending a cookie */
203
204 unsigned char *hs_msg; /*!< Reassembled handshake message */
205
206 uint32_t retransmit_timeout; /*!< Current value of timeout */
207 unsigned char retransmit_state; /*!< Retransmission state */
208 mbedtls_ssl_flight_item *flight; /*!< Current outgoing flight */
209 mbedtls_ssl_flight_item *cur_msg; /*!< Current message in flight */
210 unsigned int in_flight_start_seq; /*!< Minimum message sequence in the
211 flight being received */
212 mbedtls_ssl_transform *alt_transform_out; /*!< Alternative transform for
213 resending messages */
214 unsigned char alt_out_ctr[8]; /*!< Alternative record epoch/counter
215 for resending messages */
216#endif
217
218 /*
219 * Checksum contexts
220 */
221#if defined(MBEDTLS_SSL_PROTO_SSL3) || defined(MBEDTLS_SSL_PROTO_TLS1) || \
222 defined(MBEDTLS_SSL_PROTO_TLS1_1)
223 mbedtls_md5_context fin_md5;
224 mbedtls_sha1_context fin_sha1;
225#endif
226#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
227#if defined(MBEDTLS_SHA256_C)
228 mbedtls_sha256_context fin_sha256;
229#endif
230#if defined(MBEDTLS_SHA512_C)
231 mbedtls_sha512_context fin_sha512;
232#endif
233#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
234
235 void (*update_checksum)(mbedtls_ssl_context *, const unsigned char *, size_t);
236 void (*calc_verify)(mbedtls_ssl_context *, unsigned char *);
237 void (*calc_finished)(mbedtls_ssl_context *, unsigned char *, int);
238 int (*tls_prf)(const unsigned char *, size_t, const char *,
239 const unsigned char *, size_t,
240 unsigned char *, size_t);
241
242 size_t pmslen; /*!< premaster length */
243
244 unsigned char randbytes[64]; /*!< random bytes */
245 unsigned char premaster[MBEDTLS_PREMASTER_SIZE];
246 /*!< premaster secret */
247
248 int resume; /*!< session resume indicator*/
249 int max_major_ver; /*!< max. major version client*/
250 int max_minor_ver; /*!< max. minor version client*/
251 int cli_exts; /*!< client extension presence*/
252
253#if defined(MBEDTLS_SSL_SESSION_TICKETS)
254 int new_session_ticket; /*!< use NewSessionTicket? */
255#endif /* MBEDTLS_SSL_SESSION_TICKETS */
256#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
257 int extended_ms; /*!< use Extended Master Secret? */
258#endif
259};
260
261/*
262 * This structure contains a full set of runtime transform parameters
263 * either in negotiation or active.
264 */
265struct mbedtls_ssl_transform
266{
267 /*
268 * Session specific crypto layer
269 */
270 const mbedtls_ssl_ciphersuite_t *ciphersuite_info;
271 /*!< Chosen cipersuite_info */
Manuel Pégourié-Gonnard39a48f42015-06-18 16:06:55 +0200272 unsigned int keylen; /*!< symmetric key length (bytes) */
Manuel Pégourié-Gonnardcd4fcc62015-05-26 12:11:48 +0200273 size_t minlen; /*!< min. ciphertext length */
274 size_t ivlen; /*!< IV length */
275 size_t fixed_ivlen; /*!< Fixed part of IV (AEAD) */
276 size_t maclen; /*!< MAC length */
277
278 unsigned char iv_enc[16]; /*!< IV (encryption) */
279 unsigned char iv_dec[16]; /*!< IV (decryption) */
280
281#if defined(MBEDTLS_SSL_PROTO_SSL3)
282 /* Needed only for SSL v3.0 secret */
283 unsigned char mac_enc[20]; /*!< SSL v3.0 secret (enc) */
284 unsigned char mac_dec[20]; /*!< SSL v3.0 secret (dec) */
285#endif /* MBEDTLS_SSL_PROTO_SSL3 */
286
287 mbedtls_md_context_t md_ctx_enc; /*!< MAC (encryption) */
288 mbedtls_md_context_t md_ctx_dec; /*!< MAC (decryption) */
289
290 mbedtls_cipher_context_t cipher_ctx_enc; /*!< encryption context */
291 mbedtls_cipher_context_t cipher_ctx_dec; /*!< decryption context */
292
293 /*
294 * Session specific compression layer
295 */
296#if defined(MBEDTLS_ZLIB_SUPPORT)
297 z_stream ctx_deflate; /*!< compression context */
298 z_stream ctx_inflate; /*!< decompression context */
299#endif
300};
301
302#if defined(MBEDTLS_X509_CRT_PARSE_C)
303/*
304 * List of certificate + private key pairs
305 */
306struct mbedtls_ssl_key_cert
307{
308 mbedtls_x509_crt *cert; /*!< cert */
309 mbedtls_pk_context *key; /*!< private key */
310 mbedtls_ssl_key_cert *next; /*!< next key/cert pair */
311};
312#endif /* MBEDTLS_X509_CRT_PARSE_C */
313
314#if defined(MBEDTLS_SSL_PROTO_DTLS)
315/*
316 * List of handshake messages kept around for resending
317 */
318struct mbedtls_ssl_flight_item
319{
320 unsigned char *p; /*!< message, including handshake headers */
321 size_t len; /*!< length of p */
322 unsigned char type; /*!< type of the message: handshake or CCS */
323 mbedtls_ssl_flight_item *next; /*!< next handshake message(s) */
324};
325#endif /* MBEDTLS_SSL_PROTO_DTLS */
326
327
328/**
329 * \brief Free referenced items in an SSL transform context and clear
330 * memory
331 *
332 * \param transform SSL transform context
333 */
334void mbedtls_ssl_transform_free( mbedtls_ssl_transform *transform );
335
336/**
337 * \brief Free referenced items in an SSL handshake context and clear
338 * memory
339 *
340 * \param handshake SSL handshake context
341 */
342void mbedtls_ssl_handshake_free( mbedtls_ssl_handshake_params *handshake );
343
Manuel Pégourié-Gonnard5e94dde2015-05-26 11:57:05 +0200344int mbedtls_ssl_handshake_client_step( mbedtls_ssl_context *ssl );
345int mbedtls_ssl_handshake_server_step( mbedtls_ssl_context *ssl );
346void mbedtls_ssl_handshake_wrapup( mbedtls_ssl_context *ssl );
347
348int mbedtls_ssl_send_fatal_handshake_failure( mbedtls_ssl_context *ssl );
349
350void mbedtls_ssl_reset_checksum( mbedtls_ssl_context *ssl );
351int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl );
352
353int mbedtls_ssl_read_record( mbedtls_ssl_context *ssl );
354int mbedtls_ssl_fetch_input( mbedtls_ssl_context *ssl, size_t nb_want );
355
356int mbedtls_ssl_write_record( mbedtls_ssl_context *ssl );
357int mbedtls_ssl_flush_output( mbedtls_ssl_context *ssl );
358
359int mbedtls_ssl_parse_certificate( mbedtls_ssl_context *ssl );
360int mbedtls_ssl_write_certificate( mbedtls_ssl_context *ssl );
361
362int mbedtls_ssl_parse_change_cipher_spec( mbedtls_ssl_context *ssl );
363int mbedtls_ssl_write_change_cipher_spec( mbedtls_ssl_context *ssl );
364
365int mbedtls_ssl_parse_finished( mbedtls_ssl_context *ssl );
366int mbedtls_ssl_write_finished( mbedtls_ssl_context *ssl );
367
368void mbedtls_ssl_optimize_checksum( mbedtls_ssl_context *ssl,
369 const mbedtls_ssl_ciphersuite_t *ciphersuite_info );
370
371#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
372int mbedtls_ssl_psk_derive_premaster( mbedtls_ssl_context *ssl, mbedtls_key_exchange_type_t key_ex );
373#endif
374
375#if defined(MBEDTLS_PK_C)
376unsigned char mbedtls_ssl_sig_from_pk( mbedtls_pk_context *pk );
377mbedtls_pk_type_t mbedtls_ssl_pk_alg_from_sig( unsigned char sig );
378#endif
379
380mbedtls_md_type_t mbedtls_ssl_md_alg_from_hash( unsigned char hash );
Manuel Pégourié-Gonnard7bfc1222015-06-17 14:34:48 +0200381unsigned char mbedtls_ssl_hash_from_md_alg( int md );
Manuel Pégourié-Gonnard5e94dde2015-05-26 11:57:05 +0200382
Manuel Pégourié-Gonnardb541da62015-06-17 11:43:30 +0200383#if defined(MBEDTLS_ECP_C)
Manuel Pégourié-Gonnard9d412d82015-06-17 12:10:46 +0200384int mbedtls_ssl_check_curve( const mbedtls_ssl_context *ssl, mbedtls_ecp_group_id grp_id );
Manuel Pégourié-Gonnard5e94dde2015-05-26 11:57:05 +0200385#endif
386
Manuel Pégourié-Gonnard7bfc1222015-06-17 14:34:48 +0200387#if defined(MBEDTLS_KEY_EXCHANGE__SOME__SIGNATURE_ENABLED)
388int mbedtls_ssl_check_sig_hash( const mbedtls_ssl_context *ssl,
389 mbedtls_md_type_t md );
390#endif
391
Manuel Pégourié-Gonnard5e94dde2015-05-26 11:57:05 +0200392#if defined(MBEDTLS_X509_CRT_PARSE_C)
393static inline mbedtls_pk_context *mbedtls_ssl_own_key( mbedtls_ssl_context *ssl )
394{
395 mbedtls_ssl_key_cert *key_cert;
396
397 if( ssl->handshake != NULL && ssl->handshake->key_cert != NULL )
398 key_cert = ssl->handshake->key_cert;
399 else
400 key_cert = ssl->conf->key_cert;
401
402 return( key_cert == NULL ? NULL : key_cert->key );
403}
404
405static inline mbedtls_x509_crt *mbedtls_ssl_own_cert( mbedtls_ssl_context *ssl )
406{
407 mbedtls_ssl_key_cert *key_cert;
408
409 if( ssl->handshake != NULL && ssl->handshake->key_cert != NULL )
410 key_cert = ssl->handshake->key_cert;
411 else
412 key_cert = ssl->conf->key_cert;
413
414 return( key_cert == NULL ? NULL : key_cert->cert );
415}
416
417/*
418 * Check usage of a certificate wrt extensions:
419 * keyUsage, extendedKeyUsage (later), and nSCertType (later).
420 *
421 * Warning: cert_endpoint is the endpoint of the cert (ie, of our peer when we
422 * check a cert we received from them)!
423 *
424 * Return 0 if everything is OK, -1 if not.
425 */
426int mbedtls_ssl_check_cert_usage( const mbedtls_x509_crt *cert,
427 const mbedtls_ssl_ciphersuite_t *ciphersuite,
428 int cert_endpoint,
429 uint32_t *flags );
430#endif /* MBEDTLS_X509_CRT_PARSE_C */
431
432void mbedtls_ssl_write_version( int major, int minor, int transport,
433 unsigned char ver[2] );
434void mbedtls_ssl_read_version( int *major, int *minor, int transport,
435 const unsigned char ver[2] );
436
437static inline size_t mbedtls_ssl_hdr_len( const mbedtls_ssl_context *ssl )
438{
439#if defined(MBEDTLS_SSL_PROTO_DTLS)
440 if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
441 return( 13 );
442#else
443 ((void) ssl);
444#endif
445 return( 5 );
446}
447
448static inline size_t mbedtls_ssl_hs_hdr_len( const mbedtls_ssl_context *ssl )
449{
450#if defined(MBEDTLS_SSL_PROTO_DTLS)
451 if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
452 return( 12 );
453#else
454 ((void) ssl);
455#endif
456 return( 4 );
457}
458
459#if defined(MBEDTLS_SSL_PROTO_DTLS)
460void mbedtls_ssl_send_flight_completed( mbedtls_ssl_context *ssl );
461void mbedtls_ssl_recv_flight_completed( mbedtls_ssl_context *ssl );
462int mbedtls_ssl_resend( mbedtls_ssl_context *ssl );
463#endif
464
465/* Visible for testing purposes only */
466#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
467int mbedtls_ssl_dtls_replay_check( mbedtls_ssl_context *ssl );
468void mbedtls_ssl_dtls_replay_update( mbedtls_ssl_context *ssl );
469#endif
470
471/* constant-time buffer comparison */
472static inline int mbedtls_ssl_safer_memcmp( const void *a, const void *b, size_t n )
473{
474 size_t i;
475 const unsigned char *A = (const unsigned char *) a;
476 const unsigned char *B = (const unsigned char *) b;
477 unsigned char diff = 0;
478
479 for( i = 0; i < n; i++ )
480 diff |= A[i] ^ B[i];
481
482 return( diff );
483}
484
485#ifdef __cplusplus
486}
487#endif
488
489#endif /* ssl_internal.h */