Files
OpenCellular/host/lib/file_keys.c
Bill Richardson bc3f0b74f9 cleanup: remove a couple of unused functions and files
scripts/sign_data.sh is just a wrapper to do this:

  ./signature_digest_utility $1 $3 \
    | openssl rsautl -sign -pkcs -inkey $2

AFAICT, that script is only invoked by the SignatureFile()
function in host/lib/file_keys.c, which is not referenced by
anything. I think I can remove both of those things.

Also remove utility/gbb_utility.cc, which should have been done
long ago in commit 6f39615.

BUG=none
BRANCH=ToT
TEST=make runalltests

Also ran it on daisy_spring-paladin and link-tot-paladin.

Change-Id: I16de5022765806f11bf6144d7ffd8cc849578a68
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/216719
Reviewed-by: Mike Frysinger <vapier@chromium.org>
2014-09-12 03:39:46 +00:00

82 lines
1.9 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 functions for file and key handling.
*/
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "cryptolib.h"
#include "file_keys.h"
#include "host_common.h"
#include "signature_digest.h"
uint8_t* BufferFromFile(const char* input_file, uint64_t* len) {
int fd;
struct stat stat_fd;
uint8_t* buf = NULL;
if ((fd = open(input_file, O_RDONLY)) == -1) {
VBDEBUG(("Couldn't open file %s\n", input_file));
return NULL;
}
if (-1 == fstat(fd, &stat_fd)) {
VBDEBUG(("Couldn't stat file %s\n", input_file));
return NULL;
}
*len = stat_fd.st_size;
buf = (uint8_t*)malloc(*len);
if (!buf) {
VbExError("Couldn't allocate %ld bytes for file %s\n", *len, input_file);
return NULL;
}
if (*len != read(fd, buf, *len)) {
VBDEBUG(("Couldn't read file %s into a buffer\n", input_file));
return NULL;
}
close(fd);
return buf;
}
RSAPublicKey* RSAPublicKeyFromFile(const char* input_file) {
uint64_t len;
RSAPublicKey* key = NULL;
uint8_t* buf = BufferFromFile(input_file, &len);
if (buf)
key = RSAPublicKeyFromBuf(buf, len);
free(buf);
return key;
}
uint8_t* DigestFile(char* input_file, int sig_algorithm) {
int input_fd, len;
uint8_t data[SHA1_BLOCK_SIZE];
uint8_t* digest = NULL;
DigestContext ctx;
if( (input_fd = open(input_file, O_RDONLY)) == -1 ) {
VBDEBUG(("Couldn't open %s\n", input_file));
return NULL;
}
DigestInit(&ctx, sig_algorithm);
while ( (len = read(input_fd, data, SHA1_BLOCK_SIZE)) ==
SHA1_BLOCK_SIZE)
DigestUpdate(&ctx, data, len);
if (len != -1)
DigestUpdate(&ctx, data, len);
digest = DigestFinal(&ctx);
close(input_fd);
return digest;
}