Initial test of identicon support.
This commit is contained in:
parent
71ba6bd502
commit
17d38235a1
@ -191,7 +191,7 @@ mpw() {
|
|||||||
# library paths
|
# library paths
|
||||||
-L"." -L"lib/scrypt"
|
-L"." -L"lib/scrypt"
|
||||||
# link libraries
|
# link libraries
|
||||||
-l"crypto"
|
-l"crypto" -l"curses"
|
||||||
# scrypt
|
# scrypt
|
||||||
"lib/scrypt/scrypt-crypto_aesctr.o"
|
"lib/scrypt/scrypt-crypto_aesctr.o"
|
||||||
"lib/scrypt/scrypt-sha256.o"
|
"lib/scrypt/scrypt-sha256.o"
|
||||||
@ -248,7 +248,7 @@ mpw-bench() {
|
|||||||
### TARGETS
|
### TARGETS
|
||||||
|
|
||||||
haslib() {
|
haslib() {
|
||||||
LC_ALL=C cc -l"$1" 2>&1 | ! grep -q 'library not found'
|
! LC_ALL=C cc -l"$1" 2>&1 | grep -q 'library not found'
|
||||||
}
|
}
|
||||||
cc() {
|
cc() {
|
||||||
if hash llvm-gcc 2>/dev/null; then
|
if hash llvm-gcc 2>/dev/null; then
|
||||||
|
@ -221,6 +221,9 @@ int main(int argc, char *const argv[]) {
|
|||||||
masterPassword = getpass( "Your master password: " );
|
masterPassword = getpass( "Your master password: " );
|
||||||
trc("masterPassword: %s\n", masterPassword);
|
trc("masterPassword: %s\n", masterPassword);
|
||||||
|
|
||||||
|
// Summarize operation.
|
||||||
|
fprintf(stderr, "%s's password for %s:\n[ %s ]: ", userName, siteName, Identicon( userName, masterPassword ));
|
||||||
|
|
||||||
// Calculate the master key salt.
|
// Calculate the master key salt.
|
||||||
const char *mpKeyScope = ScopeForVariant(MPElementVariantPassword);
|
const char *mpKeyScope = ScopeForVariant(MPElementVariantPassword);
|
||||||
trc("key scope: %s\n", mpKeyScope);
|
trc("key scope: %s\n", mpKeyScope);
|
||||||
|
@ -10,9 +10,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <alg/sha256.h>
|
#include <alg/sha256.h>
|
||||||
|
|
||||||
|
#include <curses.h>
|
||||||
|
#include <term.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
const MPElementType TypeWithName(const char *typeName) {
|
const MPElementType TypeWithName(const char *typeName) {
|
||||||
@ -171,6 +175,7 @@ const char CharacterFromClass(char characterClass, uint8_t seedByte) {
|
|||||||
|
|
||||||
return classCharacters[seedByte % strlen(classCharacters)];
|
return classCharacters[seedByte % strlen(classCharacters)];
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *IDForBuf(const void *buf, size_t length) {
|
const char *IDForBuf(const void *buf, size_t length) {
|
||||||
uint8_t hash[32];
|
uint8_t hash[32];
|
||||||
SHA256_Buf(buf, length, hash);
|
SHA256_Buf(buf, length, hash);
|
||||||
@ -186,5 +191,48 @@ const char *Hex(const void *buf, size_t length) {
|
|||||||
char *id = (char *)calloc(length*2+1, sizeof(char));
|
char *id = (char *)calloc(length*2+1, sizeof(char));
|
||||||
for (int kH = 0; kH < length; kH++)
|
for (int kH = 0; kH < length; kH++)
|
||||||
sprintf(&(id[kH * 2]), "%02X", ((const uint8_t*)buf)[kH]);
|
sprintf(&(id[kH * 2]), "%02X", ((const uint8_t*)buf)[kH]);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int putvari;
|
||||||
|
char *putvarc = NULL;
|
||||||
|
static void initputvar() {
|
||||||
|
if (putvarc)
|
||||||
|
free(putvarc);
|
||||||
|
putvari=0;
|
||||||
|
putvarc=(char *)calloc(256, sizeof(char));
|
||||||
|
}
|
||||||
|
static int putvar(int c) {
|
||||||
|
putvarc[putvari++]=c;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *Identicon(const char *userName, const char *masterPassword) {
|
||||||
|
const char *left[] = { "╔", "╚", "╰", "═" };
|
||||||
|
const char *right[] = { "╗", "╝", "╯", "═" };
|
||||||
|
const char *body[] = { "█", "░", "▒", "▓", "☺", "☻" };
|
||||||
|
const char *accessory[] = { "◈", "◎", "◐", "◑", "◒", "◓", "☀", "☁", "☂", "☃", "☄", "★", "☆", "☎", "☏", "⎈", "⌂", "☘", "☢", "☣", "☕", "⌚", "⌛", "⏰", "⚡", "⛄", "⛅", "☔", "♔", "♕", "♖", "♗", "♘", "♙", "♚", "♛", "♜", "♝", "♞", "♟", "♨", "♩", "♪", "♫", "⚐", "⚑", "⚔", "⚖", "⚙", "⚠", "⌘", "⏎", "✄", "✆", "✈", "✉", "✌" };
|
||||||
|
|
||||||
|
uint8_t identiconSeed[32];
|
||||||
|
HMAC_SHA256_Buf(masterPassword, strlen(masterPassword), userName, strlen(userName), identiconSeed);
|
||||||
|
|
||||||
|
char *identicon = (char *)calloc(20, sizeof(char));
|
||||||
|
setupterm(NULL, 2, NULL);
|
||||||
|
initputvar();
|
||||||
|
tputs(tparm(tgetstr("AF", NULL), identiconSeed[4] % 7 + 1), 1, putvar);
|
||||||
|
char red[strlen(putvarc)];
|
||||||
|
strcpy(red, putvarc);
|
||||||
|
tputs(tgetstr("me", NULL), 1, putvar);
|
||||||
|
char reset[strlen(putvarc)];
|
||||||
|
strcpy(reset, putvarc);
|
||||||
|
sprintf(identicon, "%s%s%s%s%s%s",
|
||||||
|
red,
|
||||||
|
left[identiconSeed[0] % (sizeof(left) / sizeof(left[0]))],
|
||||||
|
body[identiconSeed[1] % (sizeof(body) / sizeof(body[0]))],
|
||||||
|
right[identiconSeed[2] % (sizeof(right) / sizeof(right[0]))],
|
||||||
|
accessory[identiconSeed[3] % (sizeof(accessory) / sizeof(accessory[0]))],
|
||||||
|
reset);
|
||||||
|
|
||||||
|
return identicon;
|
||||||
|
}
|
||||||
|
@ -56,4 +56,5 @@ const char *CipherForType(MPElementType type, uint8_t seedByte);
|
|||||||
const char CharacterFromClass(char characterClass, uint8_t seedByte);
|
const char CharacterFromClass(char characterClass, uint8_t seedByte);
|
||||||
const char *IDForBuf(const void *buf, size_t length);
|
const char *IDForBuf(const void *buf, size_t length);
|
||||||
const char *Hex(const void *buf, size_t length);
|
const char *Hex(const void *buf, size_t length);
|
||||||
|
const char *Identicon(const char *userName, const char *masterPassword);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user