https://bitbucket.org/daniel_fort/magic-lantern
Raw File
Tip revision: eb0c9ffde435367a5f8b090622c3b1a5f7fe66b6 authored by a1ex on 04 February 2014, 18:27:40 UTC
Close branch frenchiefilms/fix-for-issue-1742-debug-menu-shows-2-in-1391530757147
Tip revision: eb0c9ff
hash_password.c


#ifdef HOST_PROGRAM

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#define trace_write(x,...) do { 0; } while (0)
//#define trace_write(x,...) do { printf(__VA_ARGS__); printf("\n"); } while (0)

#else

#include <dryos.h>
#include <property.h>
#include <bmp.h>
#include <menu.h>
#include "../trace/trace.h"

#endif

#include "io_crypt.h"
#include "crypt_lfsr64.h"


extern uint32_t iocrypt_trace_ctx;

static void iocrypt_lfsr64_clock(uint64_t *lfsr_in, uint32_t clocks)
{
    uint64_t lfsr = *lfsr_in;
    
    for(uint32_t clock = 0; clock < clocks; clock++)
    {
        /* maximum length LFSR according to http://www.xilinx.com/support/documentation/application_notes/xapp052.pdf */
        uint32_t bit = ((lfsr >> 63) ^ (lfsr >> 62) ^ (lfsr >> 60) ^ (lfsr >> 59)) & 1;
        lfsr = (lfsr << 1) | bit;
    }
    
    *lfsr_in = lfsr;
}

void hash_password(char *password, uint64_t *hash_ret)
{
    uint64_t hash = 0xDEADBEEFDEADBEEF;
    
    /* use the password to generate an 128 bit key */
    for(uint32_t pos = 0; pos < strlen((char *)password); pos++)
    {
        uint64_t mask = 0;
        
        mask = password[pos];
        mask |= mask << 8;
        mask |= mask << 16;
        mask |= mask << 32;
        
        /* randomize random randomness with randomized random randomness */
        iocrypt_lfsr64_clock(&mask, 8192 + pos * 11 + password[pos]);
        hash ^= mask;
        iocrypt_lfsr64_clock(&hash, 8192);
    }
    
    /* some final clocking */
    iocrypt_lfsr64_clock(&hash, 8192);
    
    trace_write(iocrypt_trace_ctx, "hash_password: '%s'", password);
    trace_write(iocrypt_trace_ctx, "hash_password: 0x%08X%08X", (uint32_t)(hash>>32), (uint32_t)hash);
    
    *hash_ret = hash;
    return;
}
back to top