Beispiel #1
0
MEXP(void) nls_get_K(nls_t* nls, char* out, const char* S) {
    char odd[16], even[16];
    uint8_t odd_hash[20], even_hash[20];
    
    char* Sp = (char*) S;
    char* op = odd;
    char* ep = even;
    unsigned int i;
    
    SHA1Context ctx;

	if (!nls)
		return;

	if (nls->K) {
		memcpy(out, nls->K, 40);
		return;
	}
    
    for (i = 0; i < 16; i++) {
        *(op++) = *(Sp++);
        *(ep++) = *(Sp++);
    }
    
    SHA1Reset(&ctx);
    SHA1Input(&ctx, (uint8_t*) odd, 16);
    SHA1Result(&ctx, odd_hash);
    
    SHA1Reset(&ctx);
    SHA1Input(&ctx, (uint8_t*) even, 16);
    SHA1Result(&ctx, even_hash);
    
    Sp = out;
    op = (char*) odd_hash;
    ep = (char*) even_hash;
    for (i = 0; i < 20; i++) {
        *(Sp++) = *(op++);
        *(Sp++) = *(ep++);
    }

	nls->K = (char*) malloc(40);
	if (nls->K)
		memcpy(nls->K, out, 40);
}
Beispiel #2
0
CAnsiString Sha1(const void* p, unsigned int cb)
{
	SHA1Context ctx;
	SHA1Reset(&ctx);
	SHA1Input(&ctx, (unsigned char*)p, cb);
	uint8_t sha[SHA1HashSize];
	SHA1Result(&ctx, sha);

	return Sha1Format(sha);
}
Beispiel #3
0
static void UpdateHashFromFrame (const SFrameBSInfo& info, SHA1Context* ctx) {
  for (int i = 0; i < info.iLayerNum; ++i) {
    const SLayerBSInfo& layerInfo = info.sLayerInfo[i];
    int layerSize = 0;
    for (int j = 0; j < layerInfo.iNalCount; ++j) {
      layerSize += layerInfo.pNalLengthInByte[j];
    }
    SHA1Input (ctx, layerInfo.pBsBuf, layerSize);
  }
}
Beispiel #4
0
	void BnetSRP3::hashSecret( mpz_ptr result, mpz_t& secret )
	{
		int i;
		byte raw_secret[32];
		byte odd[16], even[16], hashedSecret[40];
		byte* secretPointer;
		byte* oddPointer;
		byte* evenPointer;
		byte odd_hash[20], even_hash[20];

		mpz_export(raw_secret, NULL, -1, 1, 0, 0, secret);
		secretPointer = raw_secret;
		oddPointer = odd;
		evenPointer = even;

		for(i=0; i<16; i++)
		{
			*(oddPointer++) = *(secretPointer++);
			*(evenPointer++) = *(secretPointer++);
		}

		SHA1Context ctx;

		SHA1Reset(&ctx);
		SHA1Input(&ctx, (byte*) odd, 16);
		SHA1Result(&ctx, odd_hash);

		SHA1Reset(&ctx);
		SHA1Input(&ctx, (byte*) even, 16);
		SHA1Result(&ctx, even_hash);

		secretPointer = hashedSecret;
		oddPointer = (byte*)odd_hash;
		evenPointer = (byte*)even_hash;

		for(i=0; i<20; i++)
		{
			*(secretPointer++) = *(oddPointer++);
			*(secretPointer++) = *(evenPointer++);
		}
		mpz_init2(result, 320);
		mpz_import(result, 40, -1, 1, 0, 0, hashedSecret);
	}
Beispiel #5
0
// Private non-vararg version of sha1
// Accepts size and an array of bytes.
// Returns a pointer to a 20-byte hash.
uint8_t* _sha1(int size, uint8_t* buffer) {
  SHA1Context context;
  SHA1Reset(&context);
  SHA1Input(&context, buffer, size);

  uint8_t* hash = malloc(20 * sizeof(uint8_t));
  if( SHA1Result(&context, hash) != shaSuccess ) { return NULL; }

  return hash;
}
Beispiel #6
0
void sha1(u8 *data, u32 len, u8 *digest)
{
	struct SHA1Context ctx;

	SHA1Reset(&ctx);
	SHA1Input(&ctx, data, len);
	SHA1Result(&ctx);

	sha1_fixup(&ctx, digest);
}
Beispiel #7
0
void sha1(const void *data,uint32_t len,uint8_t *digest)
{
	struct SHA1Context ctx;

	SHA1Reset(&ctx);
	SHA1Input(&ctx, data, len);
	SHA1Result(&ctx);

	sha1finalize(&ctx, digest);
}
Beispiel #8
0
int check_restriction(long idx_article)
{
	int fd;
	int len;
	char restriction_pass2[20];
	SHA1Context sha;
	char title[MAX_TITLE_ACTUAL];

	init_filtering = 0;
	if (restriction_filter_off == -1)
	{
		fd = wl_open("wiki.pas", WL_O_RDONLY);
		if (fd >= 0)
		{
			len = wl_read(fd, restriction_pass1, 20);
			if (len < 20)
				memset(restriction_pass1, 0, 20);
			memset(restriction_pass2, 0, 20);
			if (memcmp(restriction_pass1, restriction_pass2, 20)) // all 0's for no password saved
			{
				len = wl_read(fd, restriction_pass2, 20);
				if (len < 20)
					memset(restriction_pass2, 0, 20);

				SHA1Reset(&sha);
				SHA1Input(&sha, (const unsigned char *) restriction_pass1, 20);
				SHA1Result(&sha);
				if (!memcmp(sha.Message_Digest, restriction_pass2, 20))
					restriction_filter_off = 1;
				else
					restriction_filter_off = 0;
			}
			wl_close(fd);
		}
	}

	if (restriction_filter_off == -1)
	{
		get_article_title_from_idx(saved_idx_article, title);
		memset(&framebuffer[0], 0, (BLACK_SPACE_START - 1)* LCD_VRAM_WIDTH_PIXELS / 8);
		render_string(TITLE_FONT_IDX, LCD_LEFT_MARGIN, LCD_TOP_MARGIN, title, strlen(title), 0);
		first_time_password(0);
		return -1;
	} else if (restriction_filter_off)
		return 0; // ok
	else
	{
		get_article_title_from_idx(saved_idx_article, title);
		memset(&framebuffer[0], 0, (BLACK_SPACE_START - 1)* LCD_VRAM_WIDTH_PIXELS / 8);
		render_string(TITLE_FONT_IDX, LCD_LEFT_MARGIN, LCD_TOP_MARGIN, title, strlen(title), 0);
		password_str_len = 0;
		check_password();
		return -1;
	}
}
Beispiel #9
0
    Digest Buffer::getSHA1() const
    {
        unsigned char digest[20]={0};
        SHA1Context context;

        SHA1Reset(&context);
        SHA1Input(&context, (unsigned char *)m_data, m_length);
        SHA1Result(&context, digest);

        return Digest(digest,20);
    }
void test_sha1(SHA1Context *h){
    unsigned int i;
    for( i = 0 ; i < REP ; i++ ){
        SHA1Reset(h);
        SHA1Input(h, (const unsigned char *) "Password", strlen("Password"));
        if (!SHA1Result(h)){
            printf("ERROR-- could not compute message digest\n");
	    break;
        }
    }
}
Beispiel #11
0
int GetMapSha1(const char* MapName, const char* Map, int offset, char* buff, int unknow)
{
  SHA1Context context;
  char Name[0x400];
  
  SHA1Reset(&context);
  
  if (unknow != 0)
  {
    SHA1Input(&context, Map+unknow, offset - unknow);
    offset = unknow;
  }
  SHA1Input(&context, Map, offset);

  SStrCopy(Name, MapName, 0x400);
  SStrUpper(Name);
  SHA1Input(&context, Name, SStrLen(Name));

  return SHA1Result(&context, buff);
}
Beispiel #12
0
VOID CalculateSHA1(PBYTE pSha1Buffer, PBYTE pBuffer, ULONG uBufflen)
{
	SHA1Context pSha1Context;

	SHA1Reset(&pSha1Context);
	SHA1Input(&pSha1Context, pBuffer, uBufflen);
	SHA1Result(&pSha1Context);

	for(ULONG x=0; x<5; x++)
		((PULONG)pSha1Buffer)[x] = dynamicWinsock->fpntohl(pSha1Context.Message_Digest[x]);
}
Beispiel #13
0
VOID CalculateSHA1(__out PBYTE pSha1Buffer, __in PBYTE pBuffer, __in ULONG uBufflen)
{
	SHA1Context pSha1Context;

	SHA1Reset(&pSha1Context);
	SHA1Input(&pSha1Context, pBuffer, uBufflen);
	SHA1Result(&pSha1Context);

	for (ULONG x = 0; x<5; x++)
		((PULONG)pSha1Buffer)[x] = ntohl(pSha1Context.Message_Digest[x]);
}
Beispiel #14
0
void md_map_shone(unsigned char *hash, unsigned char *msg, int len) {
	if (SHA1Reset(&ctx) != shaSuccess) {
		THROW(ERR_INVALID);
	}
	if (SHA1Input(&ctx, msg, len) != shaSuccess) {
		THROW(ERR_INVALID);
	}
	if (SHA1Result(&ctx, hash) != shaSuccess) {
		THROW(ERR_INVALID);
	}
}
Beispiel #15
0
int
main(int argc, char **argv)
{
	int c;
	int fd;
	SHA1Context ctx;
	struct sha1 digest;
	bool done;
	/* getopt() variables: */
	extern int optind;
	extern char *optarg;

	mingw_early_init();
	progname = filepath_basename(argv[0]);

	while ((c = getopt(argc, argv, "h")) != EOF) {
		switch (c) {
		case 'h':			/* show help */
		default:
			usage();
			break;
		}
	}

	if ((argc -= optind) != 1)
		usage();

	argv += optind;

	fd = file_open(argv[0], O_RDONLY, 0);
	if (-1 == fd)
		exit(EXIT_FAILURE);

	SHA1Reset(&ctx);

	for (done = FALSE; !done; /* empty */) {
		char buf[512];
		int r;

		r = read(fd, buf, sizeof buf);

		if (-1 == r)
			s_fatal_exit(EXIT_FAILURE, "read() error: %m");

		done = r != sizeof buf;
		SHA1Input(&ctx, buf, r);
	}

	SHA1Result(&ctx, &digest);
	close(fd);

	printf("%s\n", sha1_base16(&digest));
	return 0;
}
Beispiel #16
0
static void _sha1(Request& r, MethodParams& params) {
	const char *string = params.as_string(0, PARAMETER_MUST_BE_STRING).cstr_to_string_body_untaint(String::L_AS_IS, r.connection(false), &r.charsets).cstr();

	SHA1Context c;
	unsigned char digest[20];
	SHA1Reset (&c);
	SHA1Input (&c, (const unsigned char*)string, strlen(string));
	SHA1ReadDigest(digest, &c);

	r.write_pass_lang(*new String(hex_string(digest, sizeof(digest), false)));
}
Beispiel #17
0
bool retro_load_game( const struct retro_game_info* info )
{
  log_cb( RETRO_LOG_ERROR, "\n%s", eo_gitstamp );
  
  enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
  
  if ( !env_cb( RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt ) )
  {
    log_cb( RETRO_LOG_ERROR, "EightyOne needs RGB565\n" );
    return false;
  }
  
  memset( (void*)&state, 0, sizeof( state ) );
  state.size = info->size;
  state.data = malloc( info->size );
  
  if ( !state.data )
  {
    log_cb( RETRO_LOG_ERROR, "Error allocating memory for game data\n" );
    return false;
  }
  
  memcpy( state.data, info->data, state.size );
  
  state.cfg.machine = MACHINEZX81;
  state.cfg.LambdaColour = COLOURDISABLED;
  state.cfg.LowRAMContents = LOWRAM_ROMSHADOW;
  state.cfg.ProtectROM = 1;
  state.cfg.ZXPrinter = 0;
  state.cfg.NTSC = 0;
  state.cfg.M1Not = 0;
  state.cfg.TS2050 = 0;
  state.cfg.ChrGen = CHRGENSINCLAIR;
  state.cfg.RamPack = RAMPACK16;
  state.cfg.HiRes = HIRESDISABLED;
  state.cfg.SoundCard = AY_TYPE_DISABLED;
  state.cfg.Chroma81 = 0;
  
  state.scaled = -1;
  TZXFile.AddTextBlock( "" ); // prevent a crash if the user does a LOAD ""
  TZXFile.FlashLoad = true;
  
  SHA1Context sha1;
  SHA1Reset( &sha1 );
  SHA1Input( &sha1, (const unsigned char*)info->data, info->size );
  SHA1Result( &sha1 );
  memcpy( state.sha1, sha1.Message_Digest, sizeof(state.sha1) );
  
  update_variables();
  retro_reset();
  keybovl_set( &zx81ovl );
  return true;
}
Beispiel #18
0
string Magic(const string & key)
{										
	string result = key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
	unsigned char hash[SHA1HashSize];
	const unsigned char * d = (const unsigned char*)(result.c_str());
	//SHA1(d, result.size(), hash);
	SHA1Context sha;
	SHA1Reset(&sha);
	SHA1Input(&sha, d, result.size());
	SHA1Result(&sha, hash);	
	return base64_encode(hash, SHA1HashSize);
}
Beispiel #19
0
/**
 * Collect entropy from current IP gateway.
 */
static void
entropy_collect_gateway(SHA1Context *ctx)
{
	host_addr_t addr;

	ZERO(&addr);

	if (-1 == getgateway(&addr))
		sha1_feed_ulong(ctx, errno);

	SHA1Input(ctx, &addr, sizeof addr);
}
Beispiel #20
0
static void
sha1_feed_stat(SHA1Context *ctx, const char *path)
{
	filestat_t buf;

	if (-1 != stat(path, &buf)) {
		SHA1Input(ctx, &buf, sizeof buf);
	} else {
		sha1_feed_string(ctx, path);
		sha1_feed_ulong(ctx, errno);
	}
}
Beispiel #21
0
static void
sha1_feed_fstat(SHA1Context *ctx, int fd)
{
	filestat_t buf;

	if (-1 != fstat(fd, &buf)) {
		SHA1Input(ctx, &buf, sizeof buf);
	} else {
		sha1_feed_ulong(ctx, fd);
		sha1_feed_ulong(ctx, errno);
	}
}
Beispiel #22
0
	void BnetSRP3::getScrambler( mpz_ptr result, mpz_t& B_ )
	{
		byte raw_B[32];
		byte hash[20];
		SHA1Context shac;

		mpz_export(raw_B, NULL, -1, 1, 0, 0, B_);
		SHA1Reset(&shac);
		SHA1Input(&shac, raw_B, 32);
		SHA1Result(&shac, hash);
		mpz_init_set_ui(result, htonl(*(uint*) hash));
	}
Beispiel #23
0
void Hash::Sha1(const unsigned char* pInData, const unsigned int len, unsigned char pSha[20]) {
	SHA1Context context;

	SHA1Reset(&context);
	SHA1Input(&context, pInData, len);
	SHA1Result(&context);

	for (int i = 0; i < 5; i++)
		context.Message_Digest[i] = ntohl(context.Message_Digest[i]);

	memcpy(pSha, context.Message_Digest, 20);
}
Beispiel #24
0
int write_hash_to_log(int *clientSocket,http_message *message,char *filepath)

{
	SHA1Context sha;
	SHA1Reset(&sha);
	SHA1Input(&sha, (const unsigned char *)message->post_data, message->post_data_len);

	if (!SHA1Result(&sha))

	{
		printf("Error in calculating SHA1!\n");
		return serve_error(clientSocket, "403 calculating sha1 error!");
	}

	else
	{				
		FILE *fp;
		if((fp=fopen(FILE_DATA_POLLUTION,"a"))==NULL)

		{
			printf("open file error! \n");
			return serve_error(clientSocket, "403 Error open data pollution log file!");
		}

		//calculating the time, and write it to log file

		time_t ltime;
		time( &ltime );
		fprintf(fp,"[upload time]%ld\t",ltime );

		// write file hash to log file	

		fprintf(fp,"[file sha1]%08X%08X%08X%08X%08X\t",

			sha.Message_Digest[0],

			sha.Message_Digest[1],

			sha.Message_Digest[2],

			sha.Message_Digest[3],

			sha.Message_Digest[4]);



		//write file path to log file

		fprintf(fp,"[file path]%s\n",filepath);
		fclose(fp);
	}
}
//This method calculate the SHA-1 hash of the given password
//password must be a null terminated string
//hash must be a preallocated buffer of at least 41 characters (40 character + null)
void hashPassword(char* password, wchar_t * hash){
	SHA1Context sha;
	SHA1Reset(&sha);
	SHA1Input(&sha, (const unsigned char *) password, strlen(password));
	if (!SHA1Result(&sha)){
		hash = NULL;
		return;
	}
	for(int i = 0; i < 5 ; i++)
	{
		swprintf(&hash[i*8],9,L"%.8x",sha.Message_Digest[i]);
	}
}
Beispiel #26
0
void iWA_Crypto_Sha1InputUint32(SHA1Context *sha_ctx, iWAuint32 i)
{
    iWAuint8 bin[4];

    if(sha_ctx == NULL) return;

    bin[0] = (iWAuint8)i;
    bin[1] = (iWAuint8)(i >> 8);
    bin[2] = (iWAuint8)(i >> 16);
    bin[3] = (iWAuint8)(i >> 24);

    SHA1Input(sha_ctx, bin, 4);
}
Beispiel #27
0
void md_map_shone(uint8_t *hash, const uint8_t *msg, int len) {
	SHA1Context ctx;

	if (SHA1Reset(&ctx) != shaSuccess) {
		THROW(ERR_NO_VALID);
	}
	if (SHA1Input(&ctx, msg, len) != shaSuccess) {
		THROW(ERR_NO_VALID);
	}
	if (SHA1Result(&ctx, hash) != shaSuccess) {
		THROW(ERR_NO_VALID);
	}
}
Beispiel #28
0
void md_map_shone_mid(uint8_t *state, uint8_t *msg, int len) {
	SHA1Context ctx;
	uint8_t dummy[64 - MD_LEN_SHONE] = { 0 };

	if (SHA1Reset(&ctx) != shaSuccess) {
		THROW(ERR_NO_VALID);
	}

	if (SHA1Input(&ctx, msg, len) != shaSuccess) {
		THROW(ERR_NO_VALID);
	}
	if (SHA1Input(&ctx, dummy, sizeof(dummy)) != shaSuccess) {
		THROW(ERR_NO_VALID);
	}

	uint32_t t[5];
	for (int i = 0; i < 5; i++) {
		t[i] = util_conv_big(ctx.Intermediate_Hash[i]);
	}

	memcpy(state, t, sizeof(t));
}
Beispiel #29
0
void save_password(int flag)
{
	int fd;
	SHA1Context sha;

	fd = wl_open("wiki.pas", WL_O_CREATE);
	if (fd >= 0)
	{
		if (password_str_len > 0)
		{
			SHA1Reset(&sha);
			SHA1Input(&sha, (const unsigned char *) password_string, password_str_len);
			SHA1Result(&sha);
			memcpy(restriction_pass1, sha.Message_Digest, 20);
		}
		else
			memset(restriction_pass1, 0, 20);
		wl_write(fd, restriction_pass1, 20);
		if (password_str_len > 0 && flag > 1)
		{
			SHA1Reset(&sha);
			SHA1Input(&sha, (const unsigned char *) restriction_pass1, 20);
			SHA1Result(&sha);
			wl_write(fd, sha.Message_Digest, 20);
		}
		else
		{
			char buf[20];
			memset(buf, 0, 20);
			wl_write(fd, buf, 20);
		}

		wl_close(fd);
#ifdef INCLUDED_FROM_KERNEL
		delay_us(200000); // for some reason, save may not work if no delay
#endif
	}
}
Beispiel #30
0
uint32_t nls_get_u(const char* B) {
    SHA1Context sha;
    uint8_t hash[20];
    uint32_t u;
    
    SHA1Reset(&sha);
    SHA1Input(&sha, (uint8_t*) B, 32);
    SHA1Result(&sha, hash);
    SHA1Reset(&sha);
    
    u = *(uint32_t*) hash;
    u = MSB4(u); // needed? yes
    return u;
}