Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify to use as a library. Tested in Arduino 1.0.5. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
*.*~
####################

####### C++
# Compiled Object files
*.slo
*.lo
*.o

# Compiled Dynamic libraries
*.so
*.dylib

# Compiled Static libraries
*.lai
*.la
*.a


####### C
# Object files
*.o

# Libraries
*.lib
*.a



22 changes: 5 additions & 17 deletions md2/md2.pde → md2/md2.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* MD2 */

# include <string.h>

typedef struct {
unsigned char state[48];
unsigned char checksum[16];
Expand Down Expand Up @@ -109,27 +111,13 @@ void make_digest(char *md5str, const unsigned char *digest, int len) /* {{{ */
md5str[len * 2] = '\0';
}

void do_md2(char *arg)
void do_md2(char *arg, char *returnedHash)
{
char md2str[33];
MD2_CTX context;
unsigned char digest[16];

md2str[0] = '\0';
unsigned char digest[16];
MD2Init(&context);
MD2Update(&context, (unsigned char*)arg, strlen(arg));
MD2Final(digest, &context);

make_digest(md2str, digest, 16);
Serial.println(md2str);
}

void setup() {
Serial.begin(9600);
make_digest(returnedHash, digest, 16);
}

void loop() {
do_md2("The quick brown fox jumps over the lazy dog");

delay(1000);
}
22 changes: 22 additions & 0 deletions md2/md2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* MD2 */

typedef struct {
unsigned char state[48];
unsigned char checksum[16];
unsigned char buffer[16];
char in_buffer;
} MD2_CTX;

void MD2Init(void *contextBuf);

static void MD2_Transform(void *contextBuf, const unsigned char *block);

void MD2Update(void *contextBuf, const unsigned char *buf, unsigned int len);

void MD2Final(unsigned char output[16], void *contextBuf);

void make_digest(char *md5str, const unsigned char *digest, int len);

void do_md2(char *arg, char *returnedHash);


13 changes: 13 additions & 0 deletions md2/md2.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "md2.h"

void setup() {
Serial.begin(9600);
}

void loop() {
char hash[33];
do_md2("The quick brown fox jumps over the lazy dog", hash);
Serial.println(hash);
delay(5000);
}