summaryrefslogtreecommitdiff
path: root/util/signer/publickey.cc
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2015-10-12 10:59:16 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-10-12 14:54:40 -0700
commitea48c412e09619218c56a53523c9457e6cb18204 (patch)
tree95a313a1278faba1248bbc6db85ec8fba8f55be5 /util/signer/publickey.cc
parent84e27570e961aaa248da74cc98094f7f7fa2c3e5 (diff)
downloadchrome-ec-ea48c412e09619218c56a53523c9457e6cb18204.tar.gz
cr50: upgrade to the latest FPGA image (20151012_041715@75660)
This patch updates the EC codebase to match the suggested USB build. The spiflash utility must come from the same tarball. BRANCH=none BUG=none TEST=as follows: - programmed the FPGA, it now reports the following when reset: boot_rom 20151012_041715@75660 - booted the new image using the latest spiflash version. Note that the bootrom now reports the FPGA image it comes from - disconnected the FPGA upgrade port, rebooted the device, entered on the device console: > spstp off > spste run on the workstation: $ examples/spiraw.py -l 10 -f 800000 FT232H Future Technology Devices International, Ltd initialized at 857142 hertz and observe on the DUT console: Processed 10 frames rx count 11604, tx count 5512, tx_empty 10, max rx batch 11 > Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Change-Id: I4e21151d03d1050999ea2045b2be4b99886ff15c Reviewed-on: https://chromium-review.googlesource.com/305260 Commit-Ready: Marius Schilder <mschilder@chromium.org> Reviewed-by: Marius Schilder <mschilder@chromium.org>
Diffstat (limited to 'util/signer/publickey.cc')
-rw-r--r--util/signer/publickey.cc25
1 files changed, 17 insertions, 8 deletions
diff --git a/util/signer/publickey.cc b/util/signer/publickey.cc
index 51499ab52f..97e1a8bfdf 100644
--- a/util/signer/publickey.cc
+++ b/util/signer/publickey.cc
@@ -15,6 +15,12 @@
#include <common/gnubby.h>
+extern bool FLAGS_verbose;
+
+#define VERBOSE(...) do{if(FLAGS_verbose){fprintf(stderr, __VA_ARGS__);fflush(stderr);}}while(0)
+#define WARN(...) do{fprintf(stderr, __VA_ARGS__);}while(0)
+#define FATAL(...) do{fprintf(stderr, __VA_ARGS__);abort();}while(0)
+
PublicKey::PublicKey(const std::string& filename) : key_(NULL), publicOnly_(true) {
EVP_PKEY* pkey = NULL;
BIO* bio = BIO_new(BIO_s_file());
@@ -30,14 +36,13 @@ PublicKey::PublicKey(const std::string& filename) : key_(NULL), publicOnly_(true
(void)BIO_reset(bio);
pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL);
if (pkey) {
- fprintf(stderr, "read public key only, assuming gnubby for signing..\n");
+ VERBOSE("read public key only, assuming gnubby for signing..\n");
}
}
}
if (!pkey) {
- fprintf(stderr, "loadKey: failed to load RSA key from '%s'\n",
- filename.c_str());
+ WARN("loadKey: failed to load RSA key from '%s'\n", filename.c_str());
}
BIO_free_all(bio);
@@ -152,6 +157,12 @@ void PublicKey::toArray(uint32_t* dst, size_t nwords, BIGNUM* n) {
BN_CTX_free(ctx);
}
+void PublicKey::modToArray(uint32_t* dst, size_t nwords) {
+ RSA* rsa = EVP_PKEY_get1_RSA(key_);
+ toArray(dst, nwords, rsa->n);
+ RSA_free(rsa);
+}
+
int PublicKey::encrypt(uint8_t* msg, int msglen, uint8_t* out) {
RSA* rsa = EVP_PKEY_get1_RSA(key_);
int result =
@@ -210,18 +221,16 @@ int PublicKey::sign(const void* msg, size_t msglen, BIGNUM** output) {
sig = (uint8_t*)malloc(tmplen);
if (publicOnly_) {
- fprintf(stderr, "gnubby signing..");
- fflush(stderr);
+ fprintf(stderr, "gnubby signing.."); fflush(stderr);
// TODO: 2k -> gnubby, 3k -> HSM?
Gnubby gnubby;
result = gnubby.Sign(ctx, sig, &siglen, key_);
fprintf(stderr, "gnubby.Sign: %d\n", result);
} else {
- fprintf(stderr, "ossl signing..");
- fflush(stderr);
+ VERBOSE("ossl signing..");
result = EVP_SignFinal(ctx, sig, &siglen, key_);
- fprintf(stderr, "EVP_SignFinal: %d\n", result);
+ VERBOSE("EVP_SignFinal: %d\n", result);
}
if (result != 1) goto __fail;