From e83591f188f329e9f29f2c5c59ee68a551ac454c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Tue, 15 May 2018 21:24:45 +0200 Subject: [PATCH] ec: Avoid exposing internal function --- Source/Core/Common/Crypto/ec.cpp | 8 +++++++- Source/Core/Common/Crypto/ec.h | 4 +++- Source/Core/Core/IOS/IOSC.cpp | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Source/Core/Common/Crypto/ec.cpp b/Source/Core/Common/Crypto/ec.cpp index 5fe7e9bb2b..27b9c32325 100644 --- a/Source/Core/Common/Crypto/ec.cpp +++ b/Source/Core/Common/Crypto/ec.cpp @@ -313,7 +313,7 @@ static void point_add(u8* r, const u8* p, const u8* q) elt_add(ry, s, rx); } -void point_mul(u8* d, const u8* a, const u8* b) // a is bignum +static void point_mul(u8* d, const u8* a, const u8* b) // a is bignum { u32 i; u8 mask; @@ -410,6 +410,12 @@ void ec_priv_to_pub(const u8* k, u8* Q) point_mul(Q, k, ec_G); } +std::array ComputeSharedSecret(const u8* private_key, const u8* public_key) +{ + std::array shared_secret; + point_mul(shared_secret.data(), private_key, public_key); + return shared_secret; +} #ifdef _MSC_VER #pragma warning(pop) #endif diff --git a/Source/Core/Common/Crypto/ec.h b/Source/Core/Common/Crypto/ec.h index 3bf8b9904f..da2281efda 100644 --- a/Source/Core/Common/Crypto/ec.h +++ b/Source/Core/Common/Crypto/ec.h @@ -4,10 +4,12 @@ #pragma once +#include + #include "Common/CommonTypes.h" void generate_ecdsa(u8* R, u8* S, const u8* k, const u8* hash); void ec_priv_to_pub(const u8* k, u8* Q); -void point_mul(u8* d, const u8* a, const u8* b); +std::array ComputeSharedSecret(const u8* private_key, const u8* public_key); diff --git a/Source/Core/Core/IOS/IOSC.cpp b/Source/Core/Core/IOS/IOSC.cpp index 7f47421ca8..d344e40b74 100644 --- a/Source/Core/Core/IOS/IOSC.cpp +++ b/Source/Core/Core/IOS/IOSC.cpp @@ -250,8 +250,8 @@ ReturnCode IOSC::ComputeSharedKey(Handle dest_handle, Handle private_handle, Han } // Calculate the ECC shared secret. - std::array shared_secret; - point_mul(shared_secret.data(), private_entry->data.data(), public_entry->data.data()); + const std::array shared_secret = + ComputeSharedSecret(private_entry->data.data(), public_entry->data.data()); std::array sha1; mbedtls_sha1(shared_secret.data(), shared_secret.size() / 2, sha1.data());