mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-11-26 19:25:02 +00:00
Another in a continued stream of refactoring. This change removes more of the vb1 rsa library code and associated tests, in favor of their vb2 equivalents. This change touches only host-side code and its tests, not firmware. BUG=chromium:611535 BRANCH=none TEST=make runtests; emerge-kevin coreboot depthcharge Change-Id: I1973bc2f03c60da62232e30bab0fa5fe791b6b34 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/400901
58 lines
1.5 KiB
C
58 lines
1.5 KiB
C
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*
|
|
* Utility that outputs the cryptographic digest of a contents of a
|
|
* file in a format that can be directly used to generate PKCS#1 v1.5
|
|
* signatures via the "openssl" command line utility.
|
|
*/
|
|
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "2sysincludes.h"
|
|
#include "2common.h"
|
|
|
|
#include "file_keys.h"
|
|
#include "host_common.h"
|
|
#include "padding.h"
|
|
#include "signature_digest.h"
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
int algorithm = -1;
|
|
int error_code = 0;
|
|
uint8_t* buf = NULL;
|
|
uint8_t* signature_digest = NULL;
|
|
uint32_t len;
|
|
uint32_t signature_digest_len;
|
|
|
|
if (argc != 3) {
|
|
fprintf(stderr, "Usage: %s <alg_id> <file>", argv[0]);
|
|
return -1;
|
|
}
|
|
algorithm = atoi(argv[1]);
|
|
if (algorithm < 0 || algorithm >= kNumAlgorithms) {
|
|
fprintf(stderr, "Invalid Algorithm!\n");
|
|
return -1;
|
|
}
|
|
|
|
if (VB2_SUCCESS != vb2_read_file(argv[2], &buf, &len)) {
|
|
fprintf(stderr, "Could not read file: %s\n", argv[2]);
|
|
return -1;
|
|
}
|
|
|
|
signature_digest = SignatureDigest(buf, len, algorithm);
|
|
const int digest_size = vb2_digest_size(vb2_crypto_to_hash(algorithm));
|
|
signature_digest_len = (digest_size + digestinfo_size_map[algorithm]);
|
|
if (!signature_digest)
|
|
error_code = -1;
|
|
if(signature_digest &&
|
|
1 != fwrite(signature_digest, signature_digest_len, 1, stdout))
|
|
error_code = -1;
|
|
free(signature_digest);
|
|
free(buf);
|
|
return error_code;
|
|
}
|