Commit 2128c42f authored by ='s avatar =
Browse files

Add headers for discovered rom functions

parent 59df376a
// Headers to the various functions in the rom (as we discover them)
// SHA1 is assumed to match the netbsd sha1.h headers
#define SHA1_DIGEST_LENGTH 20
#define SHA1_DIGEST_STRING_LENGTH 41
typedef struct {
uint32_t state[5];
uint32_t count[2];
uint8_t buffer[64];
} SHA1_CTX;
extern void SHA1Transform(uint32_t[5], const uint8_t[64]);
extern void SHA1Init(SHA1_CTX *);
extern void SHA1Final(uint8_t[SHA1_DIGEST_LENGTH], SHA1_CTX *);
extern void SHA1Update(SHA1_CTX *, const uint8_t *, unsigned int);
// base64_encode/decode derived by Cal
// Appears to match base64.h from netbsd wpa utils.
extern unsigned char * base64_encode(const unsigned char *src, size_t len, size_t *out_len);
extern unsigned char * base64_decode(const unsigned char *src, size_t len, size_t *out_len);
// Unfortunately it that seems to require the ROM memory management to be
// initialized because it uses mem_malloc
extern void mem_init(void * start_addr);
...@@ -6,12 +6,13 @@ ...@@ -6,12 +6,13 @@
#include "platform.h" #include "platform.h"
#include "auxmods.h" #include "auxmods.h"
#include "lrotable.h" #include "lrotable.h"
#include "c_types.h" #include "c_types.h"
#include "c_stdlib.h" #include "c_stdlib.h"
#include "user_interface.h" #include "user_interface.h"
#include "rom.h"
/** /**
* hash = crypto.sha1(input) * hash = crypto.sha1(input)
* *
...@@ -20,23 +21,22 @@ ...@@ -20,23 +21,22 @@
*/ */
static int crypto_sha1( lua_State* L ) static int crypto_sha1( lua_State* L )
{ {
// We only need a data buffer large enough to match SHA1_CTX in the rom. SHA1_CTX ctx;
// I *think* this is a 92-byte netbsd struct.
uint8_t ctx[100];
uint8_t digest[20]; uint8_t digest[20];
// Read the string from lua (with length) // Read the string from lua (with length)
int len; int len;
const char* msg = luaL_checklstring(L, 1, &len); const char* msg = luaL_checklstring(L, 1, &len);
// Use the SHA* functions in the rom // Use the SHA* functions in the rom
SHA1Init(ctx); SHA1Init(&ctx);
SHA1Update(ctx, msg, len); SHA1Update(&ctx, msg, len);
SHA1Final(digest, ctx); SHA1Final(digest, &ctx);
// Push the result as a lua string // Push the result as a lua string
lua_pushlstring(L, digest, 20); lua_pushlstring(L, digest, 20);
return 1; return 1;
} }
static const char* bytes64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const char* bytes64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/** /**
* encoded = crypto.base64Encode(raw) * encoded = crypto.base64Encode(raw)
...@@ -45,7 +45,6 @@ static const char* bytes64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx ...@@ -45,7 +45,6 @@ static const char* bytes64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx
*/ */
static int crypto_base64_encode( lua_State* L ) static int crypto_base64_encode( lua_State* L )
{ {
// TODO: figure out signature of base64_encode in rom and use that instead.
int len; int len;
const char* msg = luaL_checklstring(L, 1, &len); const char* msg = luaL_checklstring(L, 1, &len);
int blen = (len + 2) / 3 * 4; int blen = (len + 2) / 3 * 4;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment