Commit 2df26875 authored by yids's avatar yids
Browse files

started documenting pagerlib.c

parent 153fb075
......@@ -11,6 +11,12 @@
unsigned char fakeiv[] = "123456789abcdefghijklmnop";
/*
* int rng (uint8_t *dest, unsigned size)
* random number generator
* uint8_t *dest destination for the random numbers
* unsigned size number of random bytes to put in dest
*/
int rng (uint8_t *dest, unsigned size) {
#ifndef ARDUINO
int fd = open("/dev/urandom", O_RDONLY);
......@@ -41,39 +47,39 @@ int rng (uint8_t *dest, unsigned size) {
#endif
}
/*
* uint32_t compressed_point_to_addr( uint8_t input[])
* takes an compressed point and turns it into an address
* should become a proper hash function one day
*/
uint32_t compressed_point_to_addr( uint8_t input[])
{
uint32_t hashval;
int i = 0;
// DBM("hash address input", ECC_COMPRESSED_SIZE, input);
// DBM("hash address input", ECC_COMPRESSED_SIZE, input);
while( hashval < UINT32_MAX && i < ECC_COMPRESSED_SIZE ) {
// printf("hashval %u i: %u\n ", hashval, i);
hashval = hashval << 8;
hashval += input[ i ];
i++;
}
//printf("hashval %u i: %u\n ", hashval, i);
hashval = hashval << 8;
hashval += input[ i ];
i++;
}
return hashval;
// return 123456;
}
/*
* inline struct pl_ctx * pl_init()
* allocate memory for all the stuff in pl_ctx
* returns a pointer to pl_ctx
*/
inline struct pl_ctx * pl_init() {
struct pl_ctx * ctx;
ctx = (struct pl_ctx *) malloc(sizeof(struct pl_ctx));
ctx->curve = CURVE;
ctx->msg = (struct pl_pagermessage *) malloc(sizeof(struct pl_pagermessage));
memset(ctx->msg, 7, sizeof(struct pl_pagermessage));
ctx->kp = (struct pl_keypair *) malloc(sizeof(struct pl_keypair));
memset(ctx->kp, 9, sizeof(struct pl_keypair));
// ctx->keypairs = (struct list_kp *) malloc( sizeof(struct list_kp) );
uECC_set_rng(rng);
return ctx;
}
......@@ -162,6 +168,7 @@ inline int pl_send_message(struct pl_ctx *ctx) {
return 0;
}
inline int pl_receive_message(struct pl_ctx * ctx)
{
memset(&ctx->shared_secret, 7, sizeof(ctx->shared_secret));
......
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