mirror of
				https://github.com/Mbed-TLS/mbedtls.git
				synced 2025-11-03 20:33:16 +03:00 
			
		
		
		
	pkparse: parse also Weierstrass private keys using ecp_read_key()
This is to hanlde more uniformly Weierstrass and Montgomery curves. Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
		@@ -1217,15 +1217,11 @@ static int pk_parse_key_sec1_der(mbedtls_pk_context *pk,
 | 
				
			|||||||
        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
 | 
					        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Keep a reference to the position fo the private key. It will be used
 | 
				
			||||||
 | 
					     * later in this function. */
 | 
				
			||||||
    d = p;
 | 
					    d = p;
 | 
				
			||||||
    d_len = len;
 | 
					    d_len = len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if !defined(MBEDTLS_PK_USE_PSA_EC_DATA)
 | 
					 | 
				
			||||||
    if ((ret = mbedtls_mpi_read_binary(&eck->d, p, len)) != 0) {
 | 
					 | 
				
			||||||
        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    p += len;
 | 
					    p += len;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pubkey_done = 0;
 | 
					    pubkey_done = 0;
 | 
				
			||||||
@@ -1245,6 +1241,13 @@ static int pk_parse_key_sec1_der(mbedtls_pk_context *pk,
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !defined(MBEDTLS_PK_USE_PSA_EC_DATA)
 | 
				
			||||||
 | 
					    if ((ret = mbedtls_ecp_read_key(eck->grp.id, eck, d, d_len)) != 0) {
 | 
				
			||||||
 | 
					        return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PK_KEY_INVALID_FORMAT, ret);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (p != end) {
 | 
					    if (p != end) {
 | 
				
			||||||
        /*
 | 
					        /*
 | 
				
			||||||
         * Is 'publickey' present? If not, or if we can't read it (eg because it
 | 
					         * Is 'publickey' present? If not, or if we can't read it (eg because it
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user