mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-03 20:22:59 -05:00 
			
		
		
		
	Add functions to psa_util module to convert EC public keys
This commit is contained in:
		
							parent
							
								
									9c99dc862c
								
							
						
					
					
						commit
						f75f912c31
					
				@ -43,6 +43,8 @@
 | 
			
		||||
#include "pk.h"
 | 
			
		||||
#include "oid.h"
 | 
			
		||||
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
/* Translations for symmetric crypto. */
 | 
			
		||||
 | 
			
		||||
static inline psa_key_type_t mbedtls_psa_translate_cipher_type(
 | 
			
		||||
@ -352,6 +354,48 @@ static inline psa_ecc_curve_t mbedtls_psa_parse_tls_ecc_group(
 | 
			
		||||
    return( (psa_ecc_curve_t) tls_ecc_grp_reg_id );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* This function takes a buffer holding an EC public key
 | 
			
		||||
 * exported through psa_export_public_key(), and converts
 | 
			
		||||
 * it into an ECPoint structure to be put into a ClientKeyExchange
 | 
			
		||||
 * message in an ECDHE exchange.
 | 
			
		||||
 *
 | 
			
		||||
 * Both the present and the foreseeable future format of EC public keys
 | 
			
		||||
 * used by PSA have the ECPoint structure contained in the exported key
 | 
			
		||||
 * as a subbuffer, and the function merely selects this subbuffer instead
 | 
			
		||||
 * of making a copy.
 | 
			
		||||
 */
 | 
			
		||||
static inline int mbedtls_psa_tls_psa_ec_to_ecpoint( unsigned char *src,
 | 
			
		||||
                                                     size_t srclen,
 | 
			
		||||
                                                     unsigned char **dst,
 | 
			
		||||
                                                     size_t *dstlen )
 | 
			
		||||
{
 | 
			
		||||
    *dst = src;
 | 
			
		||||
    *dstlen = srclen;
 | 
			
		||||
    return( 0 );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* This function takes a buffer holding an ECPoint structure
 | 
			
		||||
 * (as contained in a TLS ServerKeyExchange message for ECDHE
 | 
			
		||||
 * exchanges) and converts it into a format that the PSA key
 | 
			
		||||
 * agreement API understands.
 | 
			
		||||
 */
 | 
			
		||||
static inline int mbedtls_psa_tls_ecpoint_to_psa_ec( psa_ecc_curve_t curve,
 | 
			
		||||
                                                     unsigned char const *src,
 | 
			
		||||
                                                     size_t srclen,
 | 
			
		||||
                                                     unsigned char *dst,
 | 
			
		||||
                                                     size_t dstlen,
 | 
			
		||||
                                                     size_t *olen )
 | 
			
		||||
{
 | 
			
		||||
    ((void) curve);
 | 
			
		||||
 | 
			
		||||
    if( srclen > dstlen )
 | 
			
		||||
        return( MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL );
 | 
			
		||||
 | 
			
		||||
    memcpy( dst, src, srclen );
 | 
			
		||||
    *olen = srclen;
 | 
			
		||||
    return( 0 );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif /* MBEDTLS_USE_PSA_CRYPTO */
 | 
			
		||||
 | 
			
		||||
#endif /* MBEDTLS_PSA_UTIL_H */
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user