Files
OpenCellular/common/utility_stub.c
Gaurav Shah f5564fa98c Vboot Reference: Refactor Code.
This CL does the following:
1) It adds a SignatureBuf function which uses the OpenSSL library to generate RSA signature. This is more robust than the previous way of invoking the command line "openssl" utility and capturing its output. No more unnecessary temporary files for signature operations.
2) It adds functions that allow direct manipulation of binary verified Firmware and Kernel Image blobs in memory.
3) It changes the structure field members for FirmwareImage to make it consistent with KernelImage. Now it's clearer which key is used when.
4) Minor bug fixes and slightly improved API for dealing verified boot firmware and kernel images.
5) Renames the RSA_verify function to prevent conflicts with OpenSSL since it's linked into the firmware utility binary.

Review URL: http://codereview.chromium.org/661353
2010-03-02 15:40:01 -08:00

71 lines
1.5 KiB
C

/* Copyright (c) 2010 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.
*
* Stub implementations of utility functions which call their linux-specific
* equivalents.
*/
#include "utility.h"
#include <stdio.h>
#include <stdlib.h>
void* Malloc(size_t size) {
void* p = malloc(size);
if (!p) {
/* Fatal Error. We must abort. */
abort();
}
return p;
}
void Free(void* ptr) {
free(ptr);
}
void* Memcpy(void* dest, const void* src, size_t n) {
return memcpy(dest, src, n);
}
void* Memset(void* dest, const uint8_t c, size_t n) {
while (n--) {
*((uint8_t*)dest++) = c;
}
return dest;
}
int SafeMemcmp(const void* s1, const void* s2, size_t n) {
int match = 0;
const unsigned char* us1 = s1;
const unsigned char* us2 = s2;
while (n--) {
if (*us1++ != *us2++)
match = 1;
}
return match;
}
void* StatefulMemcpy(MemcpyState* state, void* dst, int len) {
if (len > state->remaining_len) {
state->remaining_len = -1;
return NULL;
}
Memcpy(dst, state->remaining_buf, len);
state->remaining_buf += len;
state->remaining_len -= len;
return dst;
}
const void* StatefulMemcpy_r(MemcpyState* state, const void* src, int len) {
if (len > state->remaining_len) {
state->remaining_len = -1;
return NULL;
}
Memcpy(state->remaining_buf, src, len);
state->remaining_buf += len;
state->remaining_len -= len;
return src;
}