1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-25 19:51:52 +02:00
antorcha/fw/hash.c
Werner Almesberger 56476539cf fw/: addition of boot loader (WIP) and assorted cleanup and improvements
The boot loader currently uses the protocol switch intended for the
application. This makes it too big to fit in the very limiting
constraints the ATmega168 poses - and there's not even cryptographic
authentication yet. We'll have to dumb it down quite a bit.
2012-06-18 10:56:43 -03:00

62 lines
987 B
C

/*
* fw/hash.h - Secure hash
*
* Written 2012 by Werner Almesberger
* Copyright 2012 Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "hash.h"
#define HASH_SIZE 128
static uint8_t hash[HASH_SIZE];
void hash_init(void)
{
memset(hash, 0, HASH_SIZE);
}
void hash_merge(const uint8_t *buf, uint8_t len)
{
uint8_t i;
for (i = 0; i != len; i++)
hash[i & (HASH_SIZE-1)] ^= buf[i];
}
void hash_end(void)
{
}
bool hash_eq(const uint8_t *buf, uint8_t len, uint8_t off)
{
uint8_t i;
for (i = 0; i != len; i++)
if (hash[(off+i) & (HASH_SIZE-1)] != buf[i])
return 0;
return 1;
}
void hash_cp(uint8_t *buf, uint8_t len, uint8_t off)
{
memcpy(buf, hash+off, len);
}