Compare commits
1 Commits
1d4bb8769a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| e35d8cf136 |
@@ -8,6 +8,8 @@ DFILES = $(CFILES:.c=.d)
|
|||||||
OFILES = $(CFILES:.c=.o)
|
OFILES = $(CFILES:.c=.o)
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
|
LIBS = $(shell pkg-config --libs "openssl")
|
||||||
|
|
||||||
CFLAGS = \
|
CFLAGS = \
|
||||||
-Wall \
|
-Wall \
|
||||||
-pedantic \
|
-pedantic \
|
||||||
@@ -19,7 +21,7 @@ all: blobchain
|
|||||||
|
|
||||||
.PHONY: blobchain
|
.PHONY: blobchain
|
||||||
blobchain: $(OFILES)
|
blobchain: $(OFILES)
|
||||||
$(CC) $^ -o $@
|
$(CC) $(LIBS) $^ -o $@
|
||||||
|
|
||||||
-include $(DFILES)
|
-include $(DFILES)
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
|
|||||||
@@ -95,6 +95,9 @@ blob_list_dump(struct blob_list *lp)
|
|||||||
while (blob != NULL) {
|
while (blob != NULL) {
|
||||||
printf("blob %zd/%zd\n", count++, lp->count);
|
printf("blob %zd/%zd\n", count++, lp->count);
|
||||||
printf("... length :: %zd\n", blob->length);
|
printf("... length :: %zd\n", blob->length);
|
||||||
|
printf("... hash :: ");
|
||||||
|
dump_bytes(blob->hash, SHA256_N_BYTES);
|
||||||
|
|
||||||
printf("... data :: ");
|
printf("... data :: ");
|
||||||
dump_bytes(blob->data, blob->length < DUMP_SIZE
|
dump_bytes(blob->data, blob->length < DUMP_SIZE
|
||||||
? blob->length
|
? blob->length
|
||||||
|
|||||||
@@ -22,5 +22,6 @@ blob_allocate(struct data_stream *stmp)
|
|||||||
memcpy(bp->data, stmp->data, stmp->length);
|
memcpy(bp->data, stmp->data, stmp->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(bp->hash, stmp->hash, SHA256_N_BYTES);
|
||||||
return bp;
|
return bp;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <openssl/sha.h>
|
||||||
#include "blobchain/memlib.h"
|
#include "blobchain/memlib.h"
|
||||||
#include "blobchain/stream.h"
|
#include "blobchain/stream.h"
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@ stream_from_file(struct data_stream *stmp, const char *path)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHA256(stmp->data, stmp->length, stmp->hash);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,17 +9,20 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "blobchain/stream.h"
|
#include "blobchain/stream.h"
|
||||||
|
#include "blobchain/common.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Represents a single blob of data
|
* Represents a single blob of data
|
||||||
*
|
*
|
||||||
* @data: Buffer containing blob data
|
* @data: Buffer containing blob data
|
||||||
* @length: Length of blob
|
* @length: Length of blob
|
||||||
|
* @hash: Hash of file contents
|
||||||
* @next: Next blob
|
* @next: Next blob
|
||||||
*/
|
*/
|
||||||
struct blob {
|
struct blob {
|
||||||
void *data;
|
void *data;
|
||||||
size_t length;
|
size_t length;
|
||||||
|
uint8_t hash[SHA256_N_BYTES];
|
||||||
struct blob *next;
|
struct blob *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#ifndef BLOBCHAIN_COMMON_H
|
#ifndef BLOBCHAIN_COMMON_H
|
||||||
#define BLOBCHAIN_COMMON_H 1
|
#define BLOBCHAIN_COMMON_H 1
|
||||||
|
|
||||||
|
#define SHA256_N_BYTES 32
|
||||||
|
|
||||||
#define BLOBCHAIN_DEBUG 1
|
#define BLOBCHAIN_DEBUG 1
|
||||||
#define BLOBCHAIN_VERSION "0.0.1"
|
#define BLOBCHAIN_VERSION "0.0.1"
|
||||||
|
|
||||||
|
|||||||
@@ -6,17 +6,21 @@
|
|||||||
#ifndef BLOBCHAIN_STREAM_H
|
#ifndef BLOBCHAIN_STREAM_H
|
||||||
#define BLOBCHAIN_STREAM_H 1
|
#define BLOBCHAIN_STREAM_H 1
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include "blobchain/common.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Represents a data stream
|
* Represents a data stream
|
||||||
*
|
*
|
||||||
* @data: Data buffer
|
* @data: Data buffer
|
||||||
* @length: Number of bytes in data buffer
|
* @length: Number of bytes in data buffer
|
||||||
|
* @hash: SHA256 hash of file contents
|
||||||
*/
|
*/
|
||||||
struct data_stream {
|
struct data_stream {
|
||||||
void *data;
|
void *data;
|
||||||
size_t length;
|
size_t length;
|
||||||
|
uint8_t hash[SHA256_N_BYTES];
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user