mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 09:27:25 +00:00
dos2unix all files, we are on linux
trim them, btw... its important to start on a clean base...
This commit is contained in:
parent
a319e02b0b
commit
bb31cec957
291 changed files with 64248 additions and 64249 deletions
|
@ -1,10 +1,10 @@
|
|||
/**
|
||||
* Header file for Blake2b's internal permutation in the form of a sponge.
|
||||
* This code is based on the original Blake2b's implementation provided by
|
||||
* Header file for Blake2b's internal permutation in the form of a sponge.
|
||||
* This code is based on the original Blake2b's implementation provided by
|
||||
* Samuel Neves (https://blake2.net/)
|
||||
*
|
||||
*
|
||||
* Author: The Lyra PHC team (http://www.lyra-kdf.net/) -- 2014.
|
||||
*
|
||||
*
|
||||
* This software is hereby placed in the public domain.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#include "blake.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_blake.h"
|
||||
|
||||
|
||||
void blake_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_blake256_context ctx_blake;
|
||||
sph_blake256_init(&ctx_blake);
|
||||
sph_blake256(&ctx_blake, input, len);
|
||||
sph_blake256_close(&ctx_blake, output);
|
||||
}
|
||||
#include "blake.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_blake.h"
|
||||
|
||||
|
||||
void blake_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_blake256_context ctx_blake;
|
||||
sph_blake256_init(&ctx_blake);
|
||||
sph_blake256(&ctx_blake, input, len);
|
||||
sph_blake256_close(&ctx_blake, output);
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#ifndef BLAKE_H
|
||||
#define BLAKE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void blake_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#ifndef BLAKE_H
|
||||
#define BLAKE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void blake_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
#include "fresh.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_shavite.h"
|
||||
#include "../sha3/sph_simd.h"
|
||||
#include "../sha3/sph_echo.h"
|
||||
|
||||
void fresh_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_shavite512_context ctx_shavite1;
|
||||
sph_simd512_context ctx_simd1;
|
||||
sph_echo512_context ctx_echo1;
|
||||
|
||||
//these uint512 in the c++ source of the client are backed by an array of uint32
|
||||
uint32_t hashA[16], hashB[16];
|
||||
|
||||
sph_shavite512_init (&ctx_shavite1);
|
||||
sph_shavite512 (&ctx_shavite1, input, len);
|
||||
sph_shavite512_close(&ctx_shavite1, hashA);
|
||||
|
||||
sph_simd512_init (&ctx_simd1);
|
||||
sph_simd512 (&ctx_simd1, hashA, 64);
|
||||
sph_simd512_close(&ctx_simd1, hashB);
|
||||
|
||||
sph_shavite512_init (&ctx_shavite1);
|
||||
sph_shavite512 (&ctx_shavite1, hashB, 64);
|
||||
sph_shavite512_close(&ctx_shavite1, hashA);
|
||||
|
||||
sph_simd512_init (&ctx_simd1);
|
||||
sph_simd512 (&ctx_simd1, hashA, 64);
|
||||
sph_simd512_close(&ctx_simd1, hashB);
|
||||
|
||||
sph_echo512_init (&ctx_echo1);
|
||||
sph_echo512 (&ctx_echo1, hashB, 64);
|
||||
sph_echo512_close(&ctx_echo1, hashA);
|
||||
|
||||
memcpy(output, hashA, 32);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#include "fresh.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_shavite.h"
|
||||
#include "../sha3/sph_simd.h"
|
||||
#include "../sha3/sph_echo.h"
|
||||
|
||||
void fresh_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_shavite512_context ctx_shavite1;
|
||||
sph_simd512_context ctx_simd1;
|
||||
sph_echo512_context ctx_echo1;
|
||||
|
||||
//these uint512 in the c++ source of the client are backed by an array of uint32
|
||||
uint32_t hashA[16], hashB[16];
|
||||
|
||||
sph_shavite512_init (&ctx_shavite1);
|
||||
sph_shavite512 (&ctx_shavite1, input, len);
|
||||
sph_shavite512_close(&ctx_shavite1, hashA);
|
||||
|
||||
sph_simd512_init (&ctx_simd1);
|
||||
sph_simd512 (&ctx_simd1, hashA, 64);
|
||||
sph_simd512_close(&ctx_simd1, hashB);
|
||||
|
||||
sph_shavite512_init (&ctx_shavite1);
|
||||
sph_shavite512 (&ctx_shavite1, hashB, 64);
|
||||
sph_shavite512_close(&ctx_shavite1, hashA);
|
||||
|
||||
sph_simd512_init (&ctx_simd1);
|
||||
sph_simd512 (&ctx_simd1, hashA, 64);
|
||||
sph_simd512_close(&ctx_simd1, hashB);
|
||||
|
||||
sph_echo512_init (&ctx_echo1);
|
||||
sph_echo512 (&ctx_echo1, hashB, 64);
|
||||
sph_echo512_close(&ctx_echo1, hashA);
|
||||
|
||||
memcpy(output, hashA, 32);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#ifndef FRESH_H
|
||||
#define FRESH_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void fresh_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#ifndef FRESH_H
|
||||
#define FRESH_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void fresh_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,41 +1,41 @@
|
|||
|
||||
#include "groestl.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_groestl.h"
|
||||
#include "sha256.h"
|
||||
|
||||
void groestl_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
char hash1[64];
|
||||
char hash2[64];
|
||||
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512(&ctx_groestl, input, len);
|
||||
sph_groestl512_close(&ctx_groestl, &hash1);
|
||||
|
||||
sph_groestl512(&ctx_groestl, hash1, 64);
|
||||
sph_groestl512_close(&ctx_groestl, &hash2);
|
||||
|
||||
memcpy(output, &hash2, 32);
|
||||
}
|
||||
|
||||
void groestlmyriad_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
char temp[64];
|
||||
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512(&ctx_groestl, input, len);
|
||||
sph_groestl512_close(&ctx_groestl, &temp);
|
||||
|
||||
SHA256_CTX ctx_sha256;
|
||||
SHA256_Init(&ctx_sha256);
|
||||
SHA256_Update(&ctx_sha256, &temp, 64);
|
||||
SHA256_Final((unsigned char*) output, &ctx_sha256);
|
||||
}
|
||||
|
||||
|
||||
#include "groestl.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_groestl.h"
|
||||
#include "sha256.h"
|
||||
|
||||
void groestl_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
char hash1[64];
|
||||
char hash2[64];
|
||||
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512(&ctx_groestl, input, len);
|
||||
sph_groestl512_close(&ctx_groestl, &hash1);
|
||||
|
||||
sph_groestl512(&ctx_groestl, hash1, 64);
|
||||
sph_groestl512_close(&ctx_groestl, &hash2);
|
||||
|
||||
memcpy(output, &hash2, 32);
|
||||
}
|
||||
|
||||
void groestlmyriad_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
char temp[64];
|
||||
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512(&ctx_groestl, input, len);
|
||||
sph_groestl512_close(&ctx_groestl, &temp);
|
||||
|
||||
SHA256_CTX ctx_sha256;
|
||||
SHA256_Init(&ctx_sha256);
|
||||
SHA256_Update(&ctx_sha256, &temp, 64);
|
||||
SHA256_Final((unsigned char*) output, &ctx_sha256);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
#ifndef GROESTL_H
|
||||
#define GROESTL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void groestl_hash(const char* input, char* output, uint32_t len);
|
||||
void groestlmyriad_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef GROESTL_H
|
||||
#define GROESTL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void groestl_hash(const char* input, char* output, uint32_t len);
|
||||
void groestlmyriad_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_types.h"
|
||||
#include "../sha3/sph_keccak.h"
|
||||
|
||||
void keccak_hash(const char *input, char *output, uint32_t len)
|
||||
{
|
||||
sph_keccak256_context ctx_keccak;
|
||||
sph_keccak256_init(&ctx_keccak);
|
||||
|
||||
sph_keccak256(&ctx_keccak, input, len);
|
||||
sph_keccak256_close(&ctx_keccak, output);
|
||||
}
|
||||
|
||||
//void keccak_hash2(const char *input, char *output, uint32_t len)
|
||||
//{
|
||||
// uint32_t hashA[16];
|
||||
//
|
||||
// sph_keccak512_context ctx_keccak;
|
||||
// sph_keccak512_init(&ctx_keccak);
|
||||
//
|
||||
// sph_keccak512(&ctx_keccak, input, len);
|
||||
// sph_keccak512_close(&ctx_keccak, hashA);
|
||||
//
|
||||
// memcpy(output, hashA, 32);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_types.h"
|
||||
#include "../sha3/sph_keccak.h"
|
||||
|
||||
void keccak_hash(const char *input, char *output, uint32_t len)
|
||||
{
|
||||
sph_keccak256_context ctx_keccak;
|
||||
sph_keccak256_init(&ctx_keccak);
|
||||
|
||||
sph_keccak256(&ctx_keccak, input, len);
|
||||
sph_keccak256_close(&ctx_keccak, output);
|
||||
}
|
||||
|
||||
//void keccak_hash2(const char *input, char *output, uint32_t len)
|
||||
//{
|
||||
// uint32_t hashA[16];
|
||||
//
|
||||
// sph_keccak512_context ctx_keccak;
|
||||
// sph_keccak512_init(&ctx_keccak);
|
||||
//
|
||||
// sph_keccak512(&ctx_keccak, input, len);
|
||||
// sph_keccak512_close(&ctx_keccak, hashA);
|
||||
//
|
||||
// memcpy(output, hashA, 32);
|
||||
//}
|
||||
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#ifndef KECCAK_H
|
||||
#define KECCAK_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void keccak_hash(const char* input, char* output, uint32_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#ifndef KECCAK_H
|
||||
#define KECCAK_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void keccak_hash(const char* input, char* output, uint32_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,33 +1,33 @@
|
|||
#if (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void neoscrypt(const unsigned char *input, unsigned char *output, unsigned int profile);
|
||||
|
||||
#if (__cplusplus)
|
||||
}
|
||||
#else
|
||||
|
||||
#define SCRYPT_BLOCK_SIZE 64
|
||||
#define SCRYPT_HASH_BLOCK_SIZE 64
|
||||
#define SCRYPT_HASH_DIGEST_SIZE 32
|
||||
|
||||
typedef uint8_t hash_digest[SCRYPT_HASH_DIGEST_SIZE];
|
||||
|
||||
#define ROTL32(a,b) (((a) << (b)) | ((a) >> (32 - b)))
|
||||
#define ROTR32(a,b) (((a) >> (b)) | ((a) << (32 - b)))
|
||||
|
||||
#define U8TO32_BE(p) \
|
||||
(((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \
|
||||
((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3])))
|
||||
|
||||
#define U32TO8_BE(p, v) \
|
||||
(p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \
|
||||
(p)[2] = (uint8_t)((v) >> 8); (p)[3] = (uint8_t)((v) );
|
||||
|
||||
#define U64TO8_BE(p, v) \
|
||||
U32TO8_BE((p), (uint32_t)((v) >> 32)); \
|
||||
U32TO8_BE((p) + 4, (uint32_t)((v) ));
|
||||
|
||||
#endif
|
||||
|
||||
#if (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void neoscrypt(const unsigned char *input, unsigned char *output, unsigned int profile);
|
||||
|
||||
#if (__cplusplus)
|
||||
}
|
||||
#else
|
||||
|
||||
#define SCRYPT_BLOCK_SIZE 64
|
||||
#define SCRYPT_HASH_BLOCK_SIZE 64
|
||||
#define SCRYPT_HASH_DIGEST_SIZE 32
|
||||
|
||||
typedef uint8_t hash_digest[SCRYPT_HASH_DIGEST_SIZE];
|
||||
|
||||
#define ROTL32(a,b) (((a) << (b)) | ((a) >> (32 - b)))
|
||||
#define ROTR32(a,b) (((a) >> (b)) | ((a) << (32 - b)))
|
||||
|
||||
#define U8TO32_BE(p) \
|
||||
(((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \
|
||||
((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3])))
|
||||
|
||||
#define U32TO8_BE(p, v) \
|
||||
(p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \
|
||||
(p)[2] = (uint8_t)((v) >> 8); (p)[3] = (uint8_t)((v) );
|
||||
|
||||
#define U64TO8_BE(p, v) \
|
||||
U32TO8_BE((p), (uint32_t)((v) >> 32)); \
|
||||
U32TO8_BE((p) + 4, (uint32_t)((v) ));
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,47 +1,47 @@
|
|||
#include "nist5.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_blake.h"
|
||||
#include "../sha3/sph_groestl.h"
|
||||
#include "../sha3/sph_jh.h"
|
||||
#include "../sha3/sph_keccak.h"
|
||||
#include "../sha3/sph_skein.h"
|
||||
|
||||
|
||||
void nist5_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_skein512_context ctx_skein;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
|
||||
//these uint512 in the c++ source of the client are backed by an array of uint32
|
||||
uint32_t hash[16];
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, input, len);
|
||||
sph_blake512_close (&ctx_blake, hash);
|
||||
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, hash, 64);
|
||||
sph_groestl512_close(&ctx_groestl, hash);
|
||||
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512 (&ctx_jh, hash, 64);
|
||||
sph_jh512_close(&ctx_jh, hash);
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak, hash, 64);
|
||||
sph_keccak512_close(&ctx_keccak, hash);
|
||||
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512 (&ctx_skein, hash, 64);
|
||||
sph_skein512_close (&ctx_skein, hash);
|
||||
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
#include "nist5.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_blake.h"
|
||||
#include "../sha3/sph_groestl.h"
|
||||
#include "../sha3/sph_jh.h"
|
||||
#include "../sha3/sph_keccak.h"
|
||||
#include "../sha3/sph_skein.h"
|
||||
|
||||
|
||||
void nist5_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_skein512_context ctx_skein;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
|
||||
//these uint512 in the c++ source of the client are backed by an array of uint32
|
||||
uint32_t hash[16];
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, input, len);
|
||||
sph_blake512_close (&ctx_blake, hash);
|
||||
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, hash, 64);
|
||||
sph_groestl512_close(&ctx_groestl, hash);
|
||||
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512 (&ctx_jh, hash, 64);
|
||||
sph_jh512_close(&ctx_jh, hash);
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak, hash, 64);
|
||||
sph_keccak512_close(&ctx_keccak, hash);
|
||||
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512 (&ctx_skein, hash, 64);
|
||||
sph_skein512_close (&ctx_skein, hash);
|
||||
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#ifndef NIST5_H
|
||||
#define NIST5_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void nist5_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#ifndef NIST5_H
|
||||
#define NIST5_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void nist5_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,210 +1,210 @@
|
|||
/*-
|
||||
* Copyright 2009 Colin Percival, 2011 ArtForz, 2013 Neisklar,
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file was originally written by Colin Percival as part of the Tarsnap
|
||||
* online backup system.
|
||||
*/
|
||||
|
||||
#include "quark.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "../sha3/sph_blake.h"
|
||||
#include "../sha3/sph_bmw.h"
|
||||
#include "../sha3/sph_groestl.h"
|
||||
#include "../sha3/sph_jh.h"
|
||||
#include "../sha3/sph_keccak.h"
|
||||
#include "../sha3/sph_skein.h"
|
||||
|
||||
#if 0
|
||||
static __inline uint32_t
|
||||
be32dec(const void *pp)
|
||||
{
|
||||
const uint8_t *p = (uint8_t const *)pp;
|
||||
|
||||
return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) +
|
||||
((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
|
||||
}
|
||||
|
||||
static __inline void
|
||||
be32enc(void *pp, uint32_t x)
|
||||
{
|
||||
uint8_t * p = (uint8_t *)pp;
|
||||
|
||||
p[3] = x & 0xff;
|
||||
p[2] = (x >> 8) & 0xff;
|
||||
p[1] = (x >> 16) & 0xff;
|
||||
p[0] = (x >> 24) & 0xff;
|
||||
}
|
||||
|
||||
static __inline uint32_t
|
||||
le32dec(const void *pp)
|
||||
{
|
||||
const uint8_t *p = (uint8_t const *)pp;
|
||||
|
||||
return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) +
|
||||
((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
|
||||
}
|
||||
|
||||
static __inline void
|
||||
le32enc(void *pp, uint32_t x)
|
||||
{
|
||||
uint8_t * p = (uint8_t *)pp;
|
||||
|
||||
p[0] = x & 0xff;
|
||||
p[1] = (x >> 8) & 0xff;
|
||||
p[2] = (x >> 16) & 0xff;
|
||||
p[3] = (x >> 24) & 0xff;
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode a length len/4 vector of (uint32_t) into a length len vector of
|
||||
* (unsigned char) in big-endian form. Assumes len is a multiple of 4.
|
||||
*/
|
||||
static void
|
||||
be32enc_vect(unsigned char *dst, const uint32_t *src, uint32_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len / 4; i++)
|
||||
be32enc(dst + i * 4, src[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode a big-endian length len vector of (unsigned char) into a length
|
||||
* len/4 vector of (uint32_t). Assumes len is a multiple of 4.
|
||||
*/
|
||||
static void
|
||||
be32dec_vect(uint32_t *dst, const unsigned char *src, uint32_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len / 4; i++)
|
||||
dst[i] = be32dec(src + i * 4);
|
||||
}
|
||||
#endif
|
||||
|
||||
void quark_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_bmw512_context ctx_bmw;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_skein512_context ctx_skein;
|
||||
|
||||
uint32_t mask = 8;
|
||||
uint32_t zero = 0;
|
||||
|
||||
uint32_t hashA[16], hashB[16];
|
||||
|
||||
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, input, len);
|
||||
sph_blake512_close (&ctx_blake, hashA); //0
|
||||
|
||||
|
||||
sph_bmw512_init(&ctx_bmw);
|
||||
sph_bmw512 (&ctx_bmw, hashA, 64); //0
|
||||
sph_bmw512_close(&ctx_bmw, hashB); //1
|
||||
|
||||
|
||||
if ((hashB[0] & mask) != zero) //1
|
||||
{
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, hashB, 64); //1
|
||||
sph_groestl512_close(&ctx_groestl, hashA); //2
|
||||
}
|
||||
else
|
||||
{
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512 (&ctx_skein, hashB, 64); //1
|
||||
sph_skein512_close(&ctx_skein, hashA); //2
|
||||
}
|
||||
|
||||
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, hashA, 64); //2
|
||||
sph_groestl512_close(&ctx_groestl, hashB); //3
|
||||
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512 (&ctx_jh, hashB, 64); //3
|
||||
sph_jh512_close(&ctx_jh, hashA); //4
|
||||
|
||||
if ((hashA[0] & mask) != zero) //4
|
||||
{
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, hashA, 64); //
|
||||
sph_blake512_close(&ctx_blake, hashB); //5
|
||||
}
|
||||
else
|
||||
{
|
||||
sph_bmw512_init(&ctx_bmw);
|
||||
sph_bmw512 (&ctx_bmw, hashA, 64); //4
|
||||
sph_bmw512_close(&ctx_bmw, hashB); //5
|
||||
}
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak,hashB, 64); //5
|
||||
sph_keccak512_close(&ctx_keccak, hashA); //6
|
||||
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512 (&ctx_skein, hashA, 64); //6
|
||||
sph_skein512_close(&ctx_skein, hashB); //7
|
||||
|
||||
if ((hashB[0] & mask) != zero) //7
|
||||
{
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak, hashB, 64); //
|
||||
sph_keccak512_close(&ctx_keccak, hashA); //8
|
||||
}
|
||||
else
|
||||
{
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512 (&ctx_jh, hashB, 64); //7
|
||||
sph_jh512_close(&ctx_jh, hashA); //8
|
||||
}
|
||||
|
||||
|
||||
|
||||
memcpy(output, hashA, 32);
|
||||
|
||||
|
||||
/*
|
||||
printf("result: ");
|
||||
for (ii=0; ii < 32; ii++)
|
||||
{
|
||||
printf ("%.2x",((uint8_t*)output)[ii]);
|
||||
}
|
||||
printf ("\n");
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*-
|
||||
* Copyright 2009 Colin Percival, 2011 ArtForz, 2013 Neisklar,
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file was originally written by Colin Percival as part of the Tarsnap
|
||||
* online backup system.
|
||||
*/
|
||||
|
||||
#include "quark.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "../sha3/sph_blake.h"
|
||||
#include "../sha3/sph_bmw.h"
|
||||
#include "../sha3/sph_groestl.h"
|
||||
#include "../sha3/sph_jh.h"
|
||||
#include "../sha3/sph_keccak.h"
|
||||
#include "../sha3/sph_skein.h"
|
||||
|
||||
#if 0
|
||||
static __inline uint32_t
|
||||
be32dec(const void *pp)
|
||||
{
|
||||
const uint8_t *p = (uint8_t const *)pp;
|
||||
|
||||
return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) +
|
||||
((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
|
||||
}
|
||||
|
||||
static __inline void
|
||||
be32enc(void *pp, uint32_t x)
|
||||
{
|
||||
uint8_t * p = (uint8_t *)pp;
|
||||
|
||||
p[3] = x & 0xff;
|
||||
p[2] = (x >> 8) & 0xff;
|
||||
p[1] = (x >> 16) & 0xff;
|
||||
p[0] = (x >> 24) & 0xff;
|
||||
}
|
||||
|
||||
static __inline uint32_t
|
||||
le32dec(const void *pp)
|
||||
{
|
||||
const uint8_t *p = (uint8_t const *)pp;
|
||||
|
||||
return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) +
|
||||
((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
|
||||
}
|
||||
|
||||
static __inline void
|
||||
le32enc(void *pp, uint32_t x)
|
||||
{
|
||||
uint8_t * p = (uint8_t *)pp;
|
||||
|
||||
p[0] = x & 0xff;
|
||||
p[1] = (x >> 8) & 0xff;
|
||||
p[2] = (x >> 16) & 0xff;
|
||||
p[3] = (x >> 24) & 0xff;
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode a length len/4 vector of (uint32_t) into a length len vector of
|
||||
* (unsigned char) in big-endian form. Assumes len is a multiple of 4.
|
||||
*/
|
||||
static void
|
||||
be32enc_vect(unsigned char *dst, const uint32_t *src, uint32_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len / 4; i++)
|
||||
be32enc(dst + i * 4, src[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode a big-endian length len vector of (unsigned char) into a length
|
||||
* len/4 vector of (uint32_t). Assumes len is a multiple of 4.
|
||||
*/
|
||||
static void
|
||||
be32dec_vect(uint32_t *dst, const unsigned char *src, uint32_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len / 4; i++)
|
||||
dst[i] = be32dec(src + i * 4);
|
||||
}
|
||||
#endif
|
||||
|
||||
void quark_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_bmw512_context ctx_bmw;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_skein512_context ctx_skein;
|
||||
|
||||
uint32_t mask = 8;
|
||||
uint32_t zero = 0;
|
||||
|
||||
uint32_t hashA[16], hashB[16];
|
||||
|
||||
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, input, len);
|
||||
sph_blake512_close (&ctx_blake, hashA); //0
|
||||
|
||||
|
||||
sph_bmw512_init(&ctx_bmw);
|
||||
sph_bmw512 (&ctx_bmw, hashA, 64); //0
|
||||
sph_bmw512_close(&ctx_bmw, hashB); //1
|
||||
|
||||
|
||||
if ((hashB[0] & mask) != zero) //1
|
||||
{
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, hashB, 64); //1
|
||||
sph_groestl512_close(&ctx_groestl, hashA); //2
|
||||
}
|
||||
else
|
||||
{
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512 (&ctx_skein, hashB, 64); //1
|
||||
sph_skein512_close(&ctx_skein, hashA); //2
|
||||
}
|
||||
|
||||
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, hashA, 64); //2
|
||||
sph_groestl512_close(&ctx_groestl, hashB); //3
|
||||
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512 (&ctx_jh, hashB, 64); //3
|
||||
sph_jh512_close(&ctx_jh, hashA); //4
|
||||
|
||||
if ((hashA[0] & mask) != zero) //4
|
||||
{
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, hashA, 64); //
|
||||
sph_blake512_close(&ctx_blake, hashB); //5
|
||||
}
|
||||
else
|
||||
{
|
||||
sph_bmw512_init(&ctx_bmw);
|
||||
sph_bmw512 (&ctx_bmw, hashA, 64); //4
|
||||
sph_bmw512_close(&ctx_bmw, hashB); //5
|
||||
}
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak,hashB, 64); //5
|
||||
sph_keccak512_close(&ctx_keccak, hashA); //6
|
||||
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512 (&ctx_skein, hashA, 64); //6
|
||||
sph_skein512_close(&ctx_skein, hashB); //7
|
||||
|
||||
if ((hashB[0] & mask) != zero) //7
|
||||
{
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak, hashB, 64); //
|
||||
sph_keccak512_close(&ctx_keccak, hashA); //8
|
||||
}
|
||||
else
|
||||
{
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512 (&ctx_jh, hashB, 64); //7
|
||||
sph_jh512_close(&ctx_jh, hashA); //8
|
||||
}
|
||||
|
||||
|
||||
|
||||
memcpy(output, hashA, 32);
|
||||
|
||||
|
||||
/*
|
||||
printf("result: ");
|
||||
for (ii=0; ii < 32; ii++)
|
||||
{
|
||||
printf ("%.2x",((uint8_t*)output)[ii]);
|
||||
}
|
||||
printf ("\n");
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#ifndef QUARK_H
|
||||
#define QUARK_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void quark_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#ifndef QUARK_H
|
||||
#define QUARK_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void quark_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,44 +1,44 @@
|
|||
#include "qubit.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../sha3/sph_cubehash.h"
|
||||
#include "../sha3/sph_luffa.h"
|
||||
#include "../sha3/sph_shavite.h"
|
||||
#include "../sha3/sph_simd.h"
|
||||
#include "../sha3/sph_echo.h"
|
||||
|
||||
void qubit_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_luffa512_context ctx_luffa;
|
||||
sph_cubehash512_context ctx_cubehash;
|
||||
sph_shavite512_context ctx_shavite;
|
||||
sph_simd512_context ctx_simd;
|
||||
sph_echo512_context ctx_echo;
|
||||
|
||||
char hash1[64];
|
||||
char hash2[64];
|
||||
|
||||
sph_luffa512_init(&ctx_luffa);
|
||||
sph_luffa512(&ctx_luffa, (const void*) input, len);
|
||||
sph_luffa512_close(&ctx_luffa, (void*) &hash1); // 1
|
||||
|
||||
sph_cubehash512_init(&ctx_cubehash);
|
||||
sph_cubehash512(&ctx_cubehash, (const void*) &hash1, 64); // 1
|
||||
sph_cubehash512_close(&ctx_cubehash, (void*) &hash2); // 2
|
||||
|
||||
sph_shavite512_init(&ctx_shavite);
|
||||
sph_shavite512(&ctx_shavite, (const void*) &hash2, 64); // 3
|
||||
sph_shavite512_close(&ctx_shavite, (void*) &hash1); // 4
|
||||
|
||||
sph_simd512_init(&ctx_simd);
|
||||
sph_simd512(&ctx_simd, (const void*) &hash1, 64); // 4
|
||||
sph_simd512_close(&ctx_simd, (void*) &hash2); // 5
|
||||
|
||||
sph_echo512_init(&ctx_echo);
|
||||
sph_echo512(&ctx_echo, (const void*) &hash2, 64); // 5
|
||||
sph_echo512_close(&ctx_echo, (void*) &hash1); // 6
|
||||
|
||||
memcpy(output, &hash1, 32);
|
||||
}
|
||||
#include "qubit.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../sha3/sph_cubehash.h"
|
||||
#include "../sha3/sph_luffa.h"
|
||||
#include "../sha3/sph_shavite.h"
|
||||
#include "../sha3/sph_simd.h"
|
||||
#include "../sha3/sph_echo.h"
|
||||
|
||||
void qubit_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_luffa512_context ctx_luffa;
|
||||
sph_cubehash512_context ctx_cubehash;
|
||||
sph_shavite512_context ctx_shavite;
|
||||
sph_simd512_context ctx_simd;
|
||||
sph_echo512_context ctx_echo;
|
||||
|
||||
char hash1[64];
|
||||
char hash2[64];
|
||||
|
||||
sph_luffa512_init(&ctx_luffa);
|
||||
sph_luffa512(&ctx_luffa, (const void*) input, len);
|
||||
sph_luffa512_close(&ctx_luffa, (void*) &hash1); // 1
|
||||
|
||||
sph_cubehash512_init(&ctx_cubehash);
|
||||
sph_cubehash512(&ctx_cubehash, (const void*) &hash1, 64); // 1
|
||||
sph_cubehash512_close(&ctx_cubehash, (void*) &hash2); // 2
|
||||
|
||||
sph_shavite512_init(&ctx_shavite);
|
||||
sph_shavite512(&ctx_shavite, (const void*) &hash2, 64); // 3
|
||||
sph_shavite512_close(&ctx_shavite, (void*) &hash1); // 4
|
||||
|
||||
sph_simd512_init(&ctx_simd);
|
||||
sph_simd512(&ctx_simd, (const void*) &hash1, 64); // 4
|
||||
sph_simd512_close(&ctx_simd, (void*) &hash2); // 5
|
||||
|
||||
sph_echo512_init(&ctx_echo);
|
||||
sph_echo512(&ctx_echo, (const void*) &hash2, 64); // 5
|
||||
sph_echo512_close(&ctx_echo, (void*) &hash1); // 6
|
||||
|
||||
memcpy(output, &hash1, 32);
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#ifndef QUBIT_H
|
||||
#define QUBIT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void qubit_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef QUBIT_H
|
||||
#define QUBIT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void qubit_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,257 +1,257 @@
|
|||
/*-
|
||||
* Copyright 2009 Colin Percival, 2011 ArtForz
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file was originally written by Colin Percival as part of the Tarsnap
|
||||
* online backup system.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "scryptn.h"
|
||||
#include "sha256.h"
|
||||
|
||||
static void blkcpy(void *, void *, size_t);
|
||||
static void blkxor(void *, void *, size_t);
|
||||
static void salsa20_8(uint32_t[16]);
|
||||
static void blockmix_salsa8(uint32_t *, uint32_t *, uint32_t *, size_t);
|
||||
static uint64_t integerify(void *, size_t);
|
||||
static void smix(uint8_t *, size_t, uint64_t, uint32_t *, uint32_t *);
|
||||
|
||||
static void
|
||||
blkcpy(void * dest, void * src, size_t len)
|
||||
{
|
||||
size_t * D = (size_t *)dest;
|
||||
size_t * S = (size_t *)src;
|
||||
size_t L = len / sizeof(size_t);
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < L; i++)
|
||||
D[i] = S[i];
|
||||
}
|
||||
|
||||
static void
|
||||
blkxor(void * dest, void * src, size_t len)
|
||||
{
|
||||
size_t * D = (size_t *)dest;
|
||||
size_t * S = (size_t *)src;
|
||||
size_t L = len / sizeof(size_t);
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < L; i++)
|
||||
D[i] ^= S[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* salsa20_8(B):
|
||||
* Apply the salsa20/8 core to the provided block.
|
||||
*/
|
||||
static void
|
||||
salsa20_8(uint32_t B[16])
|
||||
{
|
||||
uint32_t x[16];
|
||||
size_t i;
|
||||
|
||||
blkcpy(x, B, 64);
|
||||
for (i = 0; i < 8; i += 2) {
|
||||
#define R(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
|
||||
/* Operate on columns. */
|
||||
x[ 4] ^= R(x[ 0]+x[12], 7); x[ 8] ^= R(x[ 4]+x[ 0], 9);
|
||||
x[12] ^= R(x[ 8]+x[ 4],13); x[ 0] ^= R(x[12]+x[ 8],18);
|
||||
|
||||
x[ 9] ^= R(x[ 5]+x[ 1], 7); x[13] ^= R(x[ 9]+x[ 5], 9);
|
||||
x[ 1] ^= R(x[13]+x[ 9],13); x[ 5] ^= R(x[ 1]+x[13],18);
|
||||
|
||||
x[14] ^= R(x[10]+x[ 6], 7); x[ 2] ^= R(x[14]+x[10], 9);
|
||||
x[ 6] ^= R(x[ 2]+x[14],13); x[10] ^= R(x[ 6]+x[ 2],18);
|
||||
|
||||
x[ 3] ^= R(x[15]+x[11], 7); x[ 7] ^= R(x[ 3]+x[15], 9);
|
||||
x[11] ^= R(x[ 7]+x[ 3],13); x[15] ^= R(x[11]+x[ 7],18);
|
||||
|
||||
/* Operate on rows. */
|
||||
x[ 1] ^= R(x[ 0]+x[ 3], 7); x[ 2] ^= R(x[ 1]+x[ 0], 9);
|
||||
x[ 3] ^= R(x[ 2]+x[ 1],13); x[ 0] ^= R(x[ 3]+x[ 2],18);
|
||||
|
||||
x[ 6] ^= R(x[ 5]+x[ 4], 7); x[ 7] ^= R(x[ 6]+x[ 5], 9);
|
||||
x[ 4] ^= R(x[ 7]+x[ 6],13); x[ 5] ^= R(x[ 4]+x[ 7],18);
|
||||
|
||||
x[11] ^= R(x[10]+x[ 9], 7); x[ 8] ^= R(x[11]+x[10], 9);
|
||||
x[ 9] ^= R(x[ 8]+x[11],13); x[10] ^= R(x[ 9]+x[ 8],18);
|
||||
|
||||
x[12] ^= R(x[15]+x[14], 7); x[13] ^= R(x[12]+x[15], 9);
|
||||
x[14] ^= R(x[13]+x[12],13); x[15] ^= R(x[14]+x[13],18);
|
||||
#undef R
|
||||
}
|
||||
for (i = 0; i < 16; i++)
|
||||
B[i] += x[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* blockmix_salsa8(Bin, Bout, X, r):
|
||||
* Compute Bout = BlockMix_{salsa20/8, r}(Bin). The input Bin must be 128r
|
||||
* bytes in length; the output Bout must also be the same size. The
|
||||
* temporary space X must be 64 bytes.
|
||||
*/
|
||||
static void
|
||||
blockmix_salsa8(uint32_t * Bin, uint32_t * Bout, uint32_t * X, size_t r)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
/* 1: X <-- B_{2r - 1} */
|
||||
blkcpy(X, &Bin[(2 * r - 1) * 16], 64);
|
||||
|
||||
/* 2: for i = 0 to 2r - 1 do */
|
||||
for (i = 0; i < 2 * r; i += 2) {
|
||||
/* 3: X <-- H(X \xor B_i) */
|
||||
blkxor(X, &Bin[i * 16], 64);
|
||||
salsa20_8(X);
|
||||
|
||||
/* 4: Y_i <-- X */
|
||||
/* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
|
||||
blkcpy(&Bout[i * 8], X, 64);
|
||||
|
||||
/* 3: X <-- H(X \xor B_i) */
|
||||
blkxor(X, &Bin[i * 16 + 16], 64);
|
||||
salsa20_8(X);
|
||||
|
||||
/* 4: Y_i <-- X */
|
||||
/* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
|
||||
blkcpy(&Bout[i * 8 + r * 16], X, 64);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* integerify(B, r):
|
||||
* Return the result of parsing B_{2r-1} as a little-endian integer.
|
||||
*/
|
||||
static uint64_t
|
||||
integerify(void * B, size_t r)
|
||||
{
|
||||
uint32_t * X = (uint32_t *)((uintptr_t)(B) + (2 * r - 1) * 64);
|
||||
|
||||
return (((uint64_t)(X[1]) << 32) + X[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* smix(B, r, N, V, XY):
|
||||
* Compute B = SMix_r(B, N). The input B must be 128r bytes in length;
|
||||
* the temporary storage V must be 128rN bytes in length; the temporary
|
||||
* storage XY must be 256r + 64 bytes in length. The value N must be a
|
||||
* power of 2 greater than 1. The arrays B, V, and XY must be aligned to a
|
||||
* multiple of 64 bytes.
|
||||
*/
|
||||
static void
|
||||
smix(uint8_t * B, size_t r, uint64_t N, uint32_t * V, uint32_t * XY)
|
||||
{
|
||||
uint32_t * X = XY;
|
||||
uint32_t * Y = &XY[32 * r];
|
||||
uint32_t * Z = &XY[64 * r];
|
||||
uint64_t i;
|
||||
uint64_t j;
|
||||
size_t k;
|
||||
|
||||
/* 1: X <-- B */
|
||||
for (k = 0; k < 32 * r; k++)
|
||||
X[k] = le32dec(&B[4 * k]);
|
||||
|
||||
/* 2: for i = 0 to N - 1 do */
|
||||
for (i = 0; i < N; i += 2) {
|
||||
/* 3: V_i <-- X */
|
||||
blkcpy(&V[i * (32 * r)], X, 128 * r);
|
||||
|
||||
/* 4: X <-- H(X) */
|
||||
blockmix_salsa8(X, Y, Z, r);
|
||||
|
||||
/* 3: V_i <-- X */
|
||||
blkcpy(&V[(i + 1) * (32 * r)], Y, 128 * r);
|
||||
|
||||
/* 4: X <-- H(X) */
|
||||
blockmix_salsa8(Y, X, Z, r);
|
||||
}
|
||||
|
||||
/* 6: for i = 0 to N - 1 do */
|
||||
for (i = 0; i < N; i += 2) {
|
||||
/* 7: j <-- Integerify(X) mod N */
|
||||
j = integerify(X, r) & (N - 1);
|
||||
|
||||
/* 8: X <-- H(X \xor V_j) */
|
||||
blkxor(X, &V[j * (32 * r)], 128 * r);
|
||||
blockmix_salsa8(X, Y, Z, r);
|
||||
|
||||
/* 7: j <-- Integerify(X) mod N */
|
||||
j = integerify(Y, r) & (N - 1);
|
||||
|
||||
/* 8: X <-- H(X \xor V_j) */
|
||||
blkxor(Y, &V[j * (32 * r)], 128 * r);
|
||||
blockmix_salsa8(Y, X, Z, r);
|
||||
}
|
||||
|
||||
/* 10: B' <-- X */
|
||||
for (k = 0; k < 32 * r; k++)
|
||||
le32enc(&B[4 * k], X[k]);
|
||||
}
|
||||
|
||||
/* cpu and memory intensive function to transform a 80 byte buffer into a 32 byte output
|
||||
scratchpad size needs to be at least 63 + (128 * r * p) + (256 * r + 64) + (128 * r * N) bytes
|
||||
*/
|
||||
void scrypt_N_R_1_256_sp(const char* input, char* output, char* scratchpad, uint32_t N, uint32_t R, uint32_t len)
|
||||
{
|
||||
uint8_t * B;
|
||||
uint32_t * V;
|
||||
uint32_t * XY;
|
||||
uint32_t i;
|
||||
|
||||
//const uint32_t N = 1024;
|
||||
uint32_t r=R;
|
||||
const uint32_t p = 1;
|
||||
|
||||
B = (uint8_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));
|
||||
XY = (uint32_t *)(B + (128 * r * p));
|
||||
V = (uint32_t *)(B + (128 * r * p) + (256 * r + 64));
|
||||
|
||||
/* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
|
||||
PBKDF2_SHA256((const uint8_t*)input, len, (const uint8_t*)input, len, 1, B, p * 128 * r);
|
||||
|
||||
/* 2: for i = 0 to p - 1 do */
|
||||
for (i = 0; i < p; i++) {
|
||||
/* 3: B_i <-- MF(B_i, N) */
|
||||
smix(&B[i * 128 * r], r, N, V, XY);
|
||||
}
|
||||
|
||||
/* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
|
||||
PBKDF2_SHA256((const uint8_t*)input, len, B, p * 128 * r, 1, (uint8_t*)output, 32);
|
||||
}
|
||||
|
||||
void scrypt_N_R_1_256(const char* input, char* output, uint32_t N, uint32_t R, uint32_t len)
|
||||
{
|
||||
//char scratchpad[131583];
|
||||
char *scratchpad;
|
||||
|
||||
// align on 4 byte boundary
|
||||
scratchpad = (char*)malloc(128*N*R + (128*R)+(256*R)+64+64);
|
||||
scrypt_N_R_1_256_sp(input, output, scratchpad, N, R, len);
|
||||
free(scratchpad);
|
||||
}
|
||||
/*-
|
||||
* Copyright 2009 Colin Percival, 2011 ArtForz
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file was originally written by Colin Percival as part of the Tarsnap
|
||||
* online backup system.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "scryptn.h"
|
||||
#include "sha256.h"
|
||||
|
||||
static void blkcpy(void *, void *, size_t);
|
||||
static void blkxor(void *, void *, size_t);
|
||||
static void salsa20_8(uint32_t[16]);
|
||||
static void blockmix_salsa8(uint32_t *, uint32_t *, uint32_t *, size_t);
|
||||
static uint64_t integerify(void *, size_t);
|
||||
static void smix(uint8_t *, size_t, uint64_t, uint32_t *, uint32_t *);
|
||||
|
||||
static void
|
||||
blkcpy(void * dest, void * src, size_t len)
|
||||
{
|
||||
size_t * D = (size_t *)dest;
|
||||
size_t * S = (size_t *)src;
|
||||
size_t L = len / sizeof(size_t);
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < L; i++)
|
||||
D[i] = S[i];
|
||||
}
|
||||
|
||||
static void
|
||||
blkxor(void * dest, void * src, size_t len)
|
||||
{
|
||||
size_t * D = (size_t *)dest;
|
||||
size_t * S = (size_t *)src;
|
||||
size_t L = len / sizeof(size_t);
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < L; i++)
|
||||
D[i] ^= S[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* salsa20_8(B):
|
||||
* Apply the salsa20/8 core to the provided block.
|
||||
*/
|
||||
static void
|
||||
salsa20_8(uint32_t B[16])
|
||||
{
|
||||
uint32_t x[16];
|
||||
size_t i;
|
||||
|
||||
blkcpy(x, B, 64);
|
||||
for (i = 0; i < 8; i += 2) {
|
||||
#define R(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
|
||||
/* Operate on columns. */
|
||||
x[ 4] ^= R(x[ 0]+x[12], 7); x[ 8] ^= R(x[ 4]+x[ 0], 9);
|
||||
x[12] ^= R(x[ 8]+x[ 4],13); x[ 0] ^= R(x[12]+x[ 8],18);
|
||||
|
||||
x[ 9] ^= R(x[ 5]+x[ 1], 7); x[13] ^= R(x[ 9]+x[ 5], 9);
|
||||
x[ 1] ^= R(x[13]+x[ 9],13); x[ 5] ^= R(x[ 1]+x[13],18);
|
||||
|
||||
x[14] ^= R(x[10]+x[ 6], 7); x[ 2] ^= R(x[14]+x[10], 9);
|
||||
x[ 6] ^= R(x[ 2]+x[14],13); x[10] ^= R(x[ 6]+x[ 2],18);
|
||||
|
||||
x[ 3] ^= R(x[15]+x[11], 7); x[ 7] ^= R(x[ 3]+x[15], 9);
|
||||
x[11] ^= R(x[ 7]+x[ 3],13); x[15] ^= R(x[11]+x[ 7],18);
|
||||
|
||||
/* Operate on rows. */
|
||||
x[ 1] ^= R(x[ 0]+x[ 3], 7); x[ 2] ^= R(x[ 1]+x[ 0], 9);
|
||||
x[ 3] ^= R(x[ 2]+x[ 1],13); x[ 0] ^= R(x[ 3]+x[ 2],18);
|
||||
|
||||
x[ 6] ^= R(x[ 5]+x[ 4], 7); x[ 7] ^= R(x[ 6]+x[ 5], 9);
|
||||
x[ 4] ^= R(x[ 7]+x[ 6],13); x[ 5] ^= R(x[ 4]+x[ 7],18);
|
||||
|
||||
x[11] ^= R(x[10]+x[ 9], 7); x[ 8] ^= R(x[11]+x[10], 9);
|
||||
x[ 9] ^= R(x[ 8]+x[11],13); x[10] ^= R(x[ 9]+x[ 8],18);
|
||||
|
||||
x[12] ^= R(x[15]+x[14], 7); x[13] ^= R(x[12]+x[15], 9);
|
||||
x[14] ^= R(x[13]+x[12],13); x[15] ^= R(x[14]+x[13],18);
|
||||
#undef R
|
||||
}
|
||||
for (i = 0; i < 16; i++)
|
||||
B[i] += x[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* blockmix_salsa8(Bin, Bout, X, r):
|
||||
* Compute Bout = BlockMix_{salsa20/8, r}(Bin). The input Bin must be 128r
|
||||
* bytes in length; the output Bout must also be the same size. The
|
||||
* temporary space X must be 64 bytes.
|
||||
*/
|
||||
static void
|
||||
blockmix_salsa8(uint32_t * Bin, uint32_t * Bout, uint32_t * X, size_t r)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
/* 1: X <-- B_{2r - 1} */
|
||||
blkcpy(X, &Bin[(2 * r - 1) * 16], 64);
|
||||
|
||||
/* 2: for i = 0 to 2r - 1 do */
|
||||
for (i = 0; i < 2 * r; i += 2) {
|
||||
/* 3: X <-- H(X \xor B_i) */
|
||||
blkxor(X, &Bin[i * 16], 64);
|
||||
salsa20_8(X);
|
||||
|
||||
/* 4: Y_i <-- X */
|
||||
/* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
|
||||
blkcpy(&Bout[i * 8], X, 64);
|
||||
|
||||
/* 3: X <-- H(X \xor B_i) */
|
||||
blkxor(X, &Bin[i * 16 + 16], 64);
|
||||
salsa20_8(X);
|
||||
|
||||
/* 4: Y_i <-- X */
|
||||
/* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
|
||||
blkcpy(&Bout[i * 8 + r * 16], X, 64);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* integerify(B, r):
|
||||
* Return the result of parsing B_{2r-1} as a little-endian integer.
|
||||
*/
|
||||
static uint64_t
|
||||
integerify(void * B, size_t r)
|
||||
{
|
||||
uint32_t * X = (uint32_t *)((uintptr_t)(B) + (2 * r - 1) * 64);
|
||||
|
||||
return (((uint64_t)(X[1]) << 32) + X[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* smix(B, r, N, V, XY):
|
||||
* Compute B = SMix_r(B, N). The input B must be 128r bytes in length;
|
||||
* the temporary storage V must be 128rN bytes in length; the temporary
|
||||
* storage XY must be 256r + 64 bytes in length. The value N must be a
|
||||
* power of 2 greater than 1. The arrays B, V, and XY must be aligned to a
|
||||
* multiple of 64 bytes.
|
||||
*/
|
||||
static void
|
||||
smix(uint8_t * B, size_t r, uint64_t N, uint32_t * V, uint32_t * XY)
|
||||
{
|
||||
uint32_t * X = XY;
|
||||
uint32_t * Y = &XY[32 * r];
|
||||
uint32_t * Z = &XY[64 * r];
|
||||
uint64_t i;
|
||||
uint64_t j;
|
||||
size_t k;
|
||||
|
||||
/* 1: X <-- B */
|
||||
for (k = 0; k < 32 * r; k++)
|
||||
X[k] = le32dec(&B[4 * k]);
|
||||
|
||||
/* 2: for i = 0 to N - 1 do */
|
||||
for (i = 0; i < N; i += 2) {
|
||||
/* 3: V_i <-- X */
|
||||
blkcpy(&V[i * (32 * r)], X, 128 * r);
|
||||
|
||||
/* 4: X <-- H(X) */
|
||||
blockmix_salsa8(X, Y, Z, r);
|
||||
|
||||
/* 3: V_i <-- X */
|
||||
blkcpy(&V[(i + 1) * (32 * r)], Y, 128 * r);
|
||||
|
||||
/* 4: X <-- H(X) */
|
||||
blockmix_salsa8(Y, X, Z, r);
|
||||
}
|
||||
|
||||
/* 6: for i = 0 to N - 1 do */
|
||||
for (i = 0; i < N; i += 2) {
|
||||
/* 7: j <-- Integerify(X) mod N */
|
||||
j = integerify(X, r) & (N - 1);
|
||||
|
||||
/* 8: X <-- H(X \xor V_j) */
|
||||
blkxor(X, &V[j * (32 * r)], 128 * r);
|
||||
blockmix_salsa8(X, Y, Z, r);
|
||||
|
||||
/* 7: j <-- Integerify(X) mod N */
|
||||
j = integerify(Y, r) & (N - 1);
|
||||
|
||||
/* 8: X <-- H(X \xor V_j) */
|
||||
blkxor(Y, &V[j * (32 * r)], 128 * r);
|
||||
blockmix_salsa8(Y, X, Z, r);
|
||||
}
|
||||
|
||||
/* 10: B' <-- X */
|
||||
for (k = 0; k < 32 * r; k++)
|
||||
le32enc(&B[4 * k], X[k]);
|
||||
}
|
||||
|
||||
/* cpu and memory intensive function to transform a 80 byte buffer into a 32 byte output
|
||||
scratchpad size needs to be at least 63 + (128 * r * p) + (256 * r + 64) + (128 * r * N) bytes
|
||||
*/
|
||||
void scrypt_N_R_1_256_sp(const char* input, char* output, char* scratchpad, uint32_t N, uint32_t R, uint32_t len)
|
||||
{
|
||||
uint8_t * B;
|
||||
uint32_t * V;
|
||||
uint32_t * XY;
|
||||
uint32_t i;
|
||||
|
||||
//const uint32_t N = 1024;
|
||||
uint32_t r=R;
|
||||
const uint32_t p = 1;
|
||||
|
||||
B = (uint8_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));
|
||||
XY = (uint32_t *)(B + (128 * r * p));
|
||||
V = (uint32_t *)(B + (128 * r * p) + (256 * r + 64));
|
||||
|
||||
/* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
|
||||
PBKDF2_SHA256((const uint8_t*)input, len, (const uint8_t*)input, len, 1, B, p * 128 * r);
|
||||
|
||||
/* 2: for i = 0 to p - 1 do */
|
||||
for (i = 0; i < p; i++) {
|
||||
/* 3: B_i <-- MF(B_i, N) */
|
||||
smix(&B[i * 128 * r], r, N, V, XY);
|
||||
}
|
||||
|
||||
/* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
|
||||
PBKDF2_SHA256((const uint8_t*)input, len, B, p * 128 * r, 1, (uint8_t*)output, 32);
|
||||
}
|
||||
|
||||
void scrypt_N_R_1_256(const char* input, char* output, uint32_t N, uint32_t R, uint32_t len)
|
||||
{
|
||||
//char scratchpad[131583];
|
||||
char *scratchpad;
|
||||
|
||||
// align on 4 byte boundary
|
||||
scratchpad = (char*)malloc(128*N*R + (128*R)+(256*R)+64+64);
|
||||
scrypt_N_R_1_256_sp(input, output, scratchpad, N, R, len);
|
||||
free(scratchpad);
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#ifndef SCRYPTN_H
|
||||
#define SCRYPTN_H
|
||||
#include <stdint.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//void scrypt_N_R_1_256(const char* input, char* output, uint32_t N, uint32_t R, uint32_t len);
|
||||
//void scrypt_N_R_1_256_sp(const char* input, char* output, char* scratchpad, uint32_t N, uint32_t R, uint32_t len);
|
||||
//const int scrypt_scratchpad_size = 131583;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#ifndef SCRYPTN_H
|
||||
#define SCRYPTN_H
|
||||
#include <stdint.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//void scrypt_N_R_1_256(const char* input, char* output, uint32_t N, uint32_t R, uint32_t len);
|
||||
//void scrypt_N_R_1_256_sp(const char* input, char* output, char* scratchpad, uint32_t N, uint32_t R, uint32_t len);
|
||||
//const int scrypt_scratchpad_size = 131583;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,287 +1,287 @@
|
|||
|
||||
//#include "stratum.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef uint8
|
||||
#define uint8 unsigned char
|
||||
#endif
|
||||
|
||||
#ifndef uint32
|
||||
#define uint32 unsigned long int
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32 total[2];
|
||||
uint32 state[8];
|
||||
uint8 buffer[64];
|
||||
}
|
||||
sha256_context;
|
||||
|
||||
//void sha256_starts( sha256_context *ctx );
|
||||
//void sha256_update( sha256_context *ctx, uint8 *input, uint32 length );
|
||||
//void sha256_finish( sha256_context *ctx, uint8 digest[32] );
|
||||
|
||||
#define GET_UINT32(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (uint32) (b)[(i) ] << 24 ) \
|
||||
| ( (uint32) (b)[(i) + 1] << 16 ) \
|
||||
| ( (uint32) (b)[(i) + 2] << 8 ) \
|
||||
| ( (uint32) (b)[(i) + 3] ); \
|
||||
}
|
||||
|
||||
#define PUT_UINT32(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (uint8) ( (n) >> 24 ); \
|
||||
(b)[(i) + 1] = (uint8) ( (n) >> 16 ); \
|
||||
(b)[(i) + 2] = (uint8) ( (n) >> 8 ); \
|
||||
(b)[(i) + 3] = (uint8) ( (n) ); \
|
||||
}
|
||||
|
||||
void sha256_starts( sha256_context *ctx )
|
||||
{
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
|
||||
ctx->state[0] = 0x6A09E667;
|
||||
ctx->state[1] = 0xBB67AE85;
|
||||
ctx->state[2] = 0x3C6EF372;
|
||||
ctx->state[3] = 0xA54FF53A;
|
||||
ctx->state[4] = 0x510E527F;
|
||||
ctx->state[5] = 0x9B05688C;
|
||||
ctx->state[6] = 0x1F83D9AB;
|
||||
ctx->state[7] = 0x5BE0CD19;
|
||||
}
|
||||
|
||||
void sha256_process( sha256_context *ctx, uint8 data[64] )
|
||||
{
|
||||
uint32 temp1, temp2, W[64];
|
||||
uint32 A, B, C, D, E, F, G, H;
|
||||
|
||||
GET_UINT32( W[0], data, 0 );
|
||||
GET_UINT32( W[1], data, 4 );
|
||||
GET_UINT32( W[2], data, 8 );
|
||||
GET_UINT32( W[3], data, 12 );
|
||||
GET_UINT32( W[4], data, 16 );
|
||||
GET_UINT32( W[5], data, 20 );
|
||||
GET_UINT32( W[6], data, 24 );
|
||||
GET_UINT32( W[7], data, 28 );
|
||||
GET_UINT32( W[8], data, 32 );
|
||||
GET_UINT32( W[9], data, 36 );
|
||||
GET_UINT32( W[10], data, 40 );
|
||||
GET_UINT32( W[11], data, 44 );
|
||||
GET_UINT32( W[12], data, 48 );
|
||||
GET_UINT32( W[13], data, 52 );
|
||||
GET_UINT32( W[14], data, 56 );
|
||||
GET_UINT32( W[15], data, 60 );
|
||||
|
||||
#define SHR(x,n) ((x & 0xFFFFFFFF) >> n)
|
||||
#define ROTR(x,n) (SHR(x,n) | (x << (32 - n)))
|
||||
|
||||
#define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3))
|
||||
#define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10))
|
||||
|
||||
#define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))
|
||||
#define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))
|
||||
|
||||
#define F0(x,y,z) ((x & y) | (z & (x | y)))
|
||||
#define F1(x,y,z) (z ^ (x & (y ^ z)))
|
||||
|
||||
#define R(t) \
|
||||
( \
|
||||
W[t] = S1(W[t - 2]) + W[t - 7] + \
|
||||
S0(W[t - 15]) + W[t - 16] \
|
||||
)
|
||||
|
||||
#define P(a,b,c,d,e,f,g,h,x,K) \
|
||||
{ \
|
||||
temp1 = h + S3(e) + F1(e,f,g) + K + x; \
|
||||
temp2 = S2(a) + F0(a,b,c); \
|
||||
d += temp1; h = temp1 + temp2; \
|
||||
}
|
||||
|
||||
A = ctx->state[0];
|
||||
B = ctx->state[1];
|
||||
C = ctx->state[2];
|
||||
D = ctx->state[3];
|
||||
E = ctx->state[4];
|
||||
F = ctx->state[5];
|
||||
G = ctx->state[6];
|
||||
H = ctx->state[7];
|
||||
|
||||
P( A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98 );
|
||||
P( H, A, B, C, D, E, F, G, W[ 1], 0x71374491 );
|
||||
P( G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF );
|
||||
P( F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5 );
|
||||
P( E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B );
|
||||
P( D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1 );
|
||||
P( C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4 );
|
||||
P( B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5 );
|
||||
P( A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98 );
|
||||
P( H, A, B, C, D, E, F, G, W[ 9], 0x12835B01 );
|
||||
P( G, H, A, B, C, D, E, F, W[10], 0x243185BE );
|
||||
P( F, G, H, A, B, C, D, E, W[11], 0x550C7DC3 );
|
||||
P( E, F, G, H, A, B, C, D, W[12], 0x72BE5D74 );
|
||||
P( D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE );
|
||||
P( C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7 );
|
||||
P( B, C, D, E, F, G, H, A, W[15], 0xC19BF174 );
|
||||
P( A, B, C, D, E, F, G, H, R(16), 0xE49B69C1 );
|
||||
P( H, A, B, C, D, E, F, G, R(17), 0xEFBE4786 );
|
||||
P( G, H, A, B, C, D, E, F, R(18), 0x0FC19DC6 );
|
||||
P( F, G, H, A, B, C, D, E, R(19), 0x240CA1CC );
|
||||
P( E, F, G, H, A, B, C, D, R(20), 0x2DE92C6F );
|
||||
P( D, E, F, G, H, A, B, C, R(21), 0x4A7484AA );
|
||||
P( C, D, E, F, G, H, A, B, R(22), 0x5CB0A9DC );
|
||||
P( B, C, D, E, F, G, H, A, R(23), 0x76F988DA );
|
||||
P( A, B, C, D, E, F, G, H, R(24), 0x983E5152 );
|
||||
P( H, A, B, C, D, E, F, G, R(25), 0xA831C66D );
|
||||
P( G, H, A, B, C, D, E, F, R(26), 0xB00327C8 );
|
||||
P( F, G, H, A, B, C, D, E, R(27), 0xBF597FC7 );
|
||||
P( E, F, G, H, A, B, C, D, R(28), 0xC6E00BF3 );
|
||||
P( D, E, F, G, H, A, B, C, R(29), 0xD5A79147 );
|
||||
P( C, D, E, F, G, H, A, B, R(30), 0x06CA6351 );
|
||||
P( B, C, D, E, F, G, H, A, R(31), 0x14292967 );
|
||||
P( A, B, C, D, E, F, G, H, R(32), 0x27B70A85 );
|
||||
P( H, A, B, C, D, E, F, G, R(33), 0x2E1B2138 );
|
||||
P( G, H, A, B, C, D, E, F, R(34), 0x4D2C6DFC );
|
||||
P( F, G, H, A, B, C, D, E, R(35), 0x53380D13 );
|
||||
P( E, F, G, H, A, B, C, D, R(36), 0x650A7354 );
|
||||
P( D, E, F, G, H, A, B, C, R(37), 0x766A0ABB );
|
||||
P( C, D, E, F, G, H, A, B, R(38), 0x81C2C92E );
|
||||
P( B, C, D, E, F, G, H, A, R(39), 0x92722C85 );
|
||||
P( A, B, C, D, E, F, G, H, R(40), 0xA2BFE8A1 );
|
||||
P( H, A, B, C, D, E, F, G, R(41), 0xA81A664B );
|
||||
P( G, H, A, B, C, D, E, F, R(42), 0xC24B8B70 );
|
||||
P( F, G, H, A, B, C, D, E, R(43), 0xC76C51A3 );
|
||||
P( E, F, G, H, A, B, C, D, R(44), 0xD192E819 );
|
||||
P( D, E, F, G, H, A, B, C, R(45), 0xD6990624 );
|
||||
P( C, D, E, F, G, H, A, B, R(46), 0xF40E3585 );
|
||||
P( B, C, D, E, F, G, H, A, R(47), 0x106AA070 );
|
||||
P( A, B, C, D, E, F, G, H, R(48), 0x19A4C116 );
|
||||
P( H, A, B, C, D, E, F, G, R(49), 0x1E376C08 );
|
||||
P( G, H, A, B, C, D, E, F, R(50), 0x2748774C );
|
||||
P( F, G, H, A, B, C, D, E, R(51), 0x34B0BCB5 );
|
||||
P( E, F, G, H, A, B, C, D, R(52), 0x391C0CB3 );
|
||||
P( D, E, F, G, H, A, B, C, R(53), 0x4ED8AA4A );
|
||||
P( C, D, E, F, G, H, A, B, R(54), 0x5B9CCA4F );
|
||||
P( B, C, D, E, F, G, H, A, R(55), 0x682E6FF3 );
|
||||
P( A, B, C, D, E, F, G, H, R(56), 0x748F82EE );
|
||||
P( H, A, B, C, D, E, F, G, R(57), 0x78A5636F );
|
||||
P( G, H, A, B, C, D, E, F, R(58), 0x84C87814 );
|
||||
P( F, G, H, A, B, C, D, E, R(59), 0x8CC70208 );
|
||||
P( E, F, G, H, A, B, C, D, R(60), 0x90BEFFFA );
|
||||
P( D, E, F, G, H, A, B, C, R(61), 0xA4506CEB );
|
||||
P( C, D, E, F, G, H, A, B, R(62), 0xBEF9A3F7 );
|
||||
P( B, C, D, E, F, G, H, A, R(63), 0xC67178F2 );
|
||||
|
||||
ctx->state[0] += A;
|
||||
ctx->state[1] += B;
|
||||
ctx->state[2] += C;
|
||||
ctx->state[3] += D;
|
||||
ctx->state[4] += E;
|
||||
ctx->state[5] += F;
|
||||
ctx->state[6] += G;
|
||||
ctx->state[7] += H;
|
||||
}
|
||||
|
||||
void sha256_update(sha256_context *ctx, uint8 *input, uint32 length)
|
||||
{
|
||||
uint32 left, fill;
|
||||
|
||||
if( ! length ) return;
|
||||
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
|
||||
ctx->total[0] += length;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
|
||||
if( ctx->total[0] < length )
|
||||
ctx->total[1]++;
|
||||
|
||||
if( left && length >= fill )
|
||||
{
|
||||
memcpy( (void *) (ctx->buffer + left),
|
||||
(void *) input, fill );
|
||||
sha256_process( ctx, ctx->buffer );
|
||||
length -= fill;
|
||||
input += fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( length >= 64 )
|
||||
{
|
||||
sha256_process( ctx, input );
|
||||
length -= 64;
|
||||
input += 64;
|
||||
}
|
||||
|
||||
if( length )
|
||||
{
|
||||
memcpy( (void *) (ctx->buffer + left),
|
||||
(void *) input, length );
|
||||
}
|
||||
}
|
||||
|
||||
static uint8 sha256_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
void sha256_finish( sha256_context *ctx, uint8 digest[32] )
|
||||
{
|
||||
uint32 last, padn;
|
||||
uint32 high, low;
|
||||
uint8 msglen[8];
|
||||
|
||||
high = ( ctx->total[0] >> 29 )
|
||||
| ( ctx->total[1] << 3 );
|
||||
low = ( ctx->total[0] << 3 );
|
||||
|
||||
PUT_UINT32( high, msglen, 0 );
|
||||
PUT_UINT32( low, msglen, 4 );
|
||||
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
|
||||
sha256_update( ctx, sha256_padding, padn );
|
||||
sha256_update( ctx, msglen, 8 );
|
||||
|
||||
PUT_UINT32( ctx->state[0], digest, 0 );
|
||||
PUT_UINT32( ctx->state[1], digest, 4 );
|
||||
PUT_UINT32( ctx->state[2], digest, 8 );
|
||||
PUT_UINT32( ctx->state[3], digest, 12 );
|
||||
PUT_UINT32( ctx->state[4], digest, 16 );
|
||||
PUT_UINT32( ctx->state[5], digest, 20 );
|
||||
PUT_UINT32( ctx->state[6], digest, 24 );
|
||||
PUT_UINT32( ctx->state[7], digest, 28 );
|
||||
}
|
||||
|
||||
void sha256_hash(const char *input, char *output, unsigned int len)
|
||||
{
|
||||
if(!len) len = strlen((const char *)input);
|
||||
|
||||
sha256_context ctx;
|
||||
sha256_starts(&ctx);
|
||||
|
||||
sha256_update(&ctx, (uint8 *)input, len);
|
||||
sha256_finish(&ctx, (unsigned char *)output);
|
||||
}
|
||||
|
||||
void sha256_double_hash(const char *input, char *output, unsigned int len)
|
||||
{
|
||||
char output1[32];
|
||||
|
||||
sha256_hash(input, output1, len);
|
||||
sha256_hash(output1, output, 32);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//#include "stratum.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef uint8
|
||||
#define uint8 unsigned char
|
||||
#endif
|
||||
|
||||
#ifndef uint32
|
||||
#define uint32 unsigned long int
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32 total[2];
|
||||
uint32 state[8];
|
||||
uint8 buffer[64];
|
||||
}
|
||||
sha256_context;
|
||||
|
||||
//void sha256_starts( sha256_context *ctx );
|
||||
//void sha256_update( sha256_context *ctx, uint8 *input, uint32 length );
|
||||
//void sha256_finish( sha256_context *ctx, uint8 digest[32] );
|
||||
|
||||
#define GET_UINT32(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (uint32) (b)[(i) ] << 24 ) \
|
||||
| ( (uint32) (b)[(i) + 1] << 16 ) \
|
||||
| ( (uint32) (b)[(i) + 2] << 8 ) \
|
||||
| ( (uint32) (b)[(i) + 3] ); \
|
||||
}
|
||||
|
||||
#define PUT_UINT32(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (uint8) ( (n) >> 24 ); \
|
||||
(b)[(i) + 1] = (uint8) ( (n) >> 16 ); \
|
||||
(b)[(i) + 2] = (uint8) ( (n) >> 8 ); \
|
||||
(b)[(i) + 3] = (uint8) ( (n) ); \
|
||||
}
|
||||
|
||||
void sha256_starts( sha256_context *ctx )
|
||||
{
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
|
||||
ctx->state[0] = 0x6A09E667;
|
||||
ctx->state[1] = 0xBB67AE85;
|
||||
ctx->state[2] = 0x3C6EF372;
|
||||
ctx->state[3] = 0xA54FF53A;
|
||||
ctx->state[4] = 0x510E527F;
|
||||
ctx->state[5] = 0x9B05688C;
|
||||
ctx->state[6] = 0x1F83D9AB;
|
||||
ctx->state[7] = 0x5BE0CD19;
|
||||
}
|
||||
|
||||
void sha256_process( sha256_context *ctx, uint8 data[64] )
|
||||
{
|
||||
uint32 temp1, temp2, W[64];
|
||||
uint32 A, B, C, D, E, F, G, H;
|
||||
|
||||
GET_UINT32( W[0], data, 0 );
|
||||
GET_UINT32( W[1], data, 4 );
|
||||
GET_UINT32( W[2], data, 8 );
|
||||
GET_UINT32( W[3], data, 12 );
|
||||
GET_UINT32( W[4], data, 16 );
|
||||
GET_UINT32( W[5], data, 20 );
|
||||
GET_UINT32( W[6], data, 24 );
|
||||
GET_UINT32( W[7], data, 28 );
|
||||
GET_UINT32( W[8], data, 32 );
|
||||
GET_UINT32( W[9], data, 36 );
|
||||
GET_UINT32( W[10], data, 40 );
|
||||
GET_UINT32( W[11], data, 44 );
|
||||
GET_UINT32( W[12], data, 48 );
|
||||
GET_UINT32( W[13], data, 52 );
|
||||
GET_UINT32( W[14], data, 56 );
|
||||
GET_UINT32( W[15], data, 60 );
|
||||
|
||||
#define SHR(x,n) ((x & 0xFFFFFFFF) >> n)
|
||||
#define ROTR(x,n) (SHR(x,n) | (x << (32 - n)))
|
||||
|
||||
#define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3))
|
||||
#define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10))
|
||||
|
||||
#define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))
|
||||
#define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))
|
||||
|
||||
#define F0(x,y,z) ((x & y) | (z & (x | y)))
|
||||
#define F1(x,y,z) (z ^ (x & (y ^ z)))
|
||||
|
||||
#define R(t) \
|
||||
( \
|
||||
W[t] = S1(W[t - 2]) + W[t - 7] + \
|
||||
S0(W[t - 15]) + W[t - 16] \
|
||||
)
|
||||
|
||||
#define P(a,b,c,d,e,f,g,h,x,K) \
|
||||
{ \
|
||||
temp1 = h + S3(e) + F1(e,f,g) + K + x; \
|
||||
temp2 = S2(a) + F0(a,b,c); \
|
||||
d += temp1; h = temp1 + temp2; \
|
||||
}
|
||||
|
||||
A = ctx->state[0];
|
||||
B = ctx->state[1];
|
||||
C = ctx->state[2];
|
||||
D = ctx->state[3];
|
||||
E = ctx->state[4];
|
||||
F = ctx->state[5];
|
||||
G = ctx->state[6];
|
||||
H = ctx->state[7];
|
||||
|
||||
P( A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98 );
|
||||
P( H, A, B, C, D, E, F, G, W[ 1], 0x71374491 );
|
||||
P( G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF );
|
||||
P( F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5 );
|
||||
P( E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B );
|
||||
P( D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1 );
|
||||
P( C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4 );
|
||||
P( B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5 );
|
||||
P( A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98 );
|
||||
P( H, A, B, C, D, E, F, G, W[ 9], 0x12835B01 );
|
||||
P( G, H, A, B, C, D, E, F, W[10], 0x243185BE );
|
||||
P( F, G, H, A, B, C, D, E, W[11], 0x550C7DC3 );
|
||||
P( E, F, G, H, A, B, C, D, W[12], 0x72BE5D74 );
|
||||
P( D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE );
|
||||
P( C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7 );
|
||||
P( B, C, D, E, F, G, H, A, W[15], 0xC19BF174 );
|
||||
P( A, B, C, D, E, F, G, H, R(16), 0xE49B69C1 );
|
||||
P( H, A, B, C, D, E, F, G, R(17), 0xEFBE4786 );
|
||||
P( G, H, A, B, C, D, E, F, R(18), 0x0FC19DC6 );
|
||||
P( F, G, H, A, B, C, D, E, R(19), 0x240CA1CC );
|
||||
P( E, F, G, H, A, B, C, D, R(20), 0x2DE92C6F );
|
||||
P( D, E, F, G, H, A, B, C, R(21), 0x4A7484AA );
|
||||
P( C, D, E, F, G, H, A, B, R(22), 0x5CB0A9DC );
|
||||
P( B, C, D, E, F, G, H, A, R(23), 0x76F988DA );
|
||||
P( A, B, C, D, E, F, G, H, R(24), 0x983E5152 );
|
||||
P( H, A, B, C, D, E, F, G, R(25), 0xA831C66D );
|
||||
P( G, H, A, B, C, D, E, F, R(26), 0xB00327C8 );
|
||||
P( F, G, H, A, B, C, D, E, R(27), 0xBF597FC7 );
|
||||
P( E, F, G, H, A, B, C, D, R(28), 0xC6E00BF3 );
|
||||
P( D, E, F, G, H, A, B, C, R(29), 0xD5A79147 );
|
||||
P( C, D, E, F, G, H, A, B, R(30), 0x06CA6351 );
|
||||
P( B, C, D, E, F, G, H, A, R(31), 0x14292967 );
|
||||
P( A, B, C, D, E, F, G, H, R(32), 0x27B70A85 );
|
||||
P( H, A, B, C, D, E, F, G, R(33), 0x2E1B2138 );
|
||||
P( G, H, A, B, C, D, E, F, R(34), 0x4D2C6DFC );
|
||||
P( F, G, H, A, B, C, D, E, R(35), 0x53380D13 );
|
||||
P( E, F, G, H, A, B, C, D, R(36), 0x650A7354 );
|
||||
P( D, E, F, G, H, A, B, C, R(37), 0x766A0ABB );
|
||||
P( C, D, E, F, G, H, A, B, R(38), 0x81C2C92E );
|
||||
P( B, C, D, E, F, G, H, A, R(39), 0x92722C85 );
|
||||
P( A, B, C, D, E, F, G, H, R(40), 0xA2BFE8A1 );
|
||||
P( H, A, B, C, D, E, F, G, R(41), 0xA81A664B );
|
||||
P( G, H, A, B, C, D, E, F, R(42), 0xC24B8B70 );
|
||||
P( F, G, H, A, B, C, D, E, R(43), 0xC76C51A3 );
|
||||
P( E, F, G, H, A, B, C, D, R(44), 0xD192E819 );
|
||||
P( D, E, F, G, H, A, B, C, R(45), 0xD6990624 );
|
||||
P( C, D, E, F, G, H, A, B, R(46), 0xF40E3585 );
|
||||
P( B, C, D, E, F, G, H, A, R(47), 0x106AA070 );
|
||||
P( A, B, C, D, E, F, G, H, R(48), 0x19A4C116 );
|
||||
P( H, A, B, C, D, E, F, G, R(49), 0x1E376C08 );
|
||||
P( G, H, A, B, C, D, E, F, R(50), 0x2748774C );
|
||||
P( F, G, H, A, B, C, D, E, R(51), 0x34B0BCB5 );
|
||||
P( E, F, G, H, A, B, C, D, R(52), 0x391C0CB3 );
|
||||
P( D, E, F, G, H, A, B, C, R(53), 0x4ED8AA4A );
|
||||
P( C, D, E, F, G, H, A, B, R(54), 0x5B9CCA4F );
|
||||
P( B, C, D, E, F, G, H, A, R(55), 0x682E6FF3 );
|
||||
P( A, B, C, D, E, F, G, H, R(56), 0x748F82EE );
|
||||
P( H, A, B, C, D, E, F, G, R(57), 0x78A5636F );
|
||||
P( G, H, A, B, C, D, E, F, R(58), 0x84C87814 );
|
||||
P( F, G, H, A, B, C, D, E, R(59), 0x8CC70208 );
|
||||
P( E, F, G, H, A, B, C, D, R(60), 0x90BEFFFA );
|
||||
P( D, E, F, G, H, A, B, C, R(61), 0xA4506CEB );
|
||||
P( C, D, E, F, G, H, A, B, R(62), 0xBEF9A3F7 );
|
||||
P( B, C, D, E, F, G, H, A, R(63), 0xC67178F2 );
|
||||
|
||||
ctx->state[0] += A;
|
||||
ctx->state[1] += B;
|
||||
ctx->state[2] += C;
|
||||
ctx->state[3] += D;
|
||||
ctx->state[4] += E;
|
||||
ctx->state[5] += F;
|
||||
ctx->state[6] += G;
|
||||
ctx->state[7] += H;
|
||||
}
|
||||
|
||||
void sha256_update(sha256_context *ctx, uint8 *input, uint32 length)
|
||||
{
|
||||
uint32 left, fill;
|
||||
|
||||
if( ! length ) return;
|
||||
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
|
||||
ctx->total[0] += length;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
|
||||
if( ctx->total[0] < length )
|
||||
ctx->total[1]++;
|
||||
|
||||
if( left && length >= fill )
|
||||
{
|
||||
memcpy( (void *) (ctx->buffer + left),
|
||||
(void *) input, fill );
|
||||
sha256_process( ctx, ctx->buffer );
|
||||
length -= fill;
|
||||
input += fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( length >= 64 )
|
||||
{
|
||||
sha256_process( ctx, input );
|
||||
length -= 64;
|
||||
input += 64;
|
||||
}
|
||||
|
||||
if( length )
|
||||
{
|
||||
memcpy( (void *) (ctx->buffer + left),
|
||||
(void *) input, length );
|
||||
}
|
||||
}
|
||||
|
||||
static uint8 sha256_padding[64] =
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
void sha256_finish( sha256_context *ctx, uint8 digest[32] )
|
||||
{
|
||||
uint32 last, padn;
|
||||
uint32 high, low;
|
||||
uint8 msglen[8];
|
||||
|
||||
high = ( ctx->total[0] >> 29 )
|
||||
| ( ctx->total[1] << 3 );
|
||||
low = ( ctx->total[0] << 3 );
|
||||
|
||||
PUT_UINT32( high, msglen, 0 );
|
||||
PUT_UINT32( low, msglen, 4 );
|
||||
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
|
||||
sha256_update( ctx, sha256_padding, padn );
|
||||
sha256_update( ctx, msglen, 8 );
|
||||
|
||||
PUT_UINT32( ctx->state[0], digest, 0 );
|
||||
PUT_UINT32( ctx->state[1], digest, 4 );
|
||||
PUT_UINT32( ctx->state[2], digest, 8 );
|
||||
PUT_UINT32( ctx->state[3], digest, 12 );
|
||||
PUT_UINT32( ctx->state[4], digest, 16 );
|
||||
PUT_UINT32( ctx->state[5], digest, 20 );
|
||||
PUT_UINT32( ctx->state[6], digest, 24 );
|
||||
PUT_UINT32( ctx->state[7], digest, 28 );
|
||||
}
|
||||
|
||||
void sha256_hash(const char *input, char *output, unsigned int len)
|
||||
{
|
||||
if(!len) len = strlen((const char *)input);
|
||||
|
||||
sha256_context ctx;
|
||||
sha256_starts(&ctx);
|
||||
|
||||
sha256_update(&ctx, (uint8 *)input, len);
|
||||
sha256_finish(&ctx, (unsigned char *)output);
|
||||
}
|
||||
|
||||
void sha256_double_hash(const char *input, char *output, unsigned int len)
|
||||
{
|
||||
char output1[32];
|
||||
|
||||
sha256_hash(input, output1, len);
|
||||
sha256_hash(output1, output, 32);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,440 +1,440 @@
|
|||
#ifndef SHA256_H
|
||||
#define SHA256_H
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
#include "stdint.h"
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static __inline uint32_t
|
||||
be32dec(const void *pp)
|
||||
{
|
||||
const uint8_t *p = (uint8_t const *)pp;
|
||||
|
||||
return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) +
|
||||
((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
|
||||
}
|
||||
|
||||
static __inline void
|
||||
be32enc(void *pp, uint32_t x)
|
||||
{
|
||||
uint8_t * p = (uint8_t *)pp;
|
||||
|
||||
p[3] = x & 0xff;
|
||||
p[2] = (x >> 8) & 0xff;
|
||||
p[1] = (x >> 16) & 0xff;
|
||||
p[0] = (x >> 24) & 0xff;
|
||||
}
|
||||
|
||||
static __inline uint32_t
|
||||
le32dec(const void *pp)
|
||||
{
|
||||
const uint8_t *p = (uint8_t const *)pp;
|
||||
|
||||
return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) +
|
||||
((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
|
||||
}
|
||||
|
||||
static __inline void
|
||||
le32enc(void *pp, uint32_t x)
|
||||
{
|
||||
uint8_t * p = (uint8_t *)pp;
|
||||
|
||||
p[0] = x & 0xff;
|
||||
p[1] = (x >> 8) & 0xff;
|
||||
p[2] = (x >> 16) & 0xff;
|
||||
p[3] = (x >> 24) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
typedef struct SHA256Context {
|
||||
uint32_t state[8];
|
||||
uint32_t count[2];
|
||||
unsigned char buf[64];
|
||||
} SHA256_CTX;
|
||||
|
||||
typedef struct HMAC_SHA256Context {
|
||||
SHA256_CTX ictx;
|
||||
SHA256_CTX octx;
|
||||
} HMAC_SHA256_CTX;
|
||||
|
||||
/*
|
||||
* Encode a length len/4 vector of (uint32_t) into a length len vector of
|
||||
* (unsigned char) in big-endian form. Assumes len is a multiple of 4.
|
||||
*/
|
||||
static void
|
||||
be32enc_vect(unsigned char *dst, const uint32_t *src, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len / 4; i++)
|
||||
be32enc(dst + i * 4, src[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode a big-endian length len vector of (unsigned char) into a length
|
||||
* len/4 vector of (uint32_t). Assumes len is a multiple of 4.
|
||||
*/
|
||||
static void
|
||||
be32dec_vect(uint32_t *dst, const unsigned char *src, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len / 4; i++)
|
||||
dst[i] = be32dec(src + i * 4);
|
||||
}
|
||||
|
||||
/* Elementary functions used by SHA256 */
|
||||
#define Ch(x, y, z) ((x & (y ^ z)) ^ z)
|
||||
#define Maj(x, y, z) ((x & (y | z)) | (y & z))
|
||||
#define SHR(x, n) (x >> n)
|
||||
#define ROTR(x, n) ((x >> n) | (x << (32 - n)))
|
||||
#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
|
||||
#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
|
||||
#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3))
|
||||
#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10))
|
||||
|
||||
/* SHA256 round function */
|
||||
#define RND(a, b, c, d, e, f, g, h, k) \
|
||||
t0 = h + S1(e) + Ch(e, f, g) + k; \
|
||||
t1 = S0(a) + Maj(a, b, c); \
|
||||
d += t0; \
|
||||
h = t0 + t1;
|
||||
|
||||
/* Adjusted round function for rotating state */
|
||||
#define RNDr(S, W, i, k) \
|
||||
RND(S[(64 - i) % 8], S[(65 - i) % 8], \
|
||||
S[(66 - i) % 8], S[(67 - i) % 8], \
|
||||
S[(68 - i) % 8], S[(69 - i) % 8], \
|
||||
S[(70 - i) % 8], S[(71 - i) % 8], \
|
||||
W[i] + k)
|
||||
|
||||
/*
|
||||
* SHA256 block compression function. The 256-bit state is transformed via
|
||||
* the 512-bit input block to produce a new state.
|
||||
*/
|
||||
static void
|
||||
SHA256_Transform(uint32_t * state, const unsigned char block[64])
|
||||
{
|
||||
uint32_t W[64];
|
||||
uint32_t S[8];
|
||||
uint32_t t0, t1;
|
||||
int i;
|
||||
|
||||
/* 1. Prepare message schedule W. */
|
||||
be32dec_vect(W, block, 64);
|
||||
for (i = 16; i < 64; i++)
|
||||
W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16];
|
||||
|
||||
/* 2. Initialize working variables. */
|
||||
memcpy(S, state, 32);
|
||||
|
||||
/* 3. Mix. */
|
||||
RNDr(S, W, 0, 0x428a2f98);
|
||||
RNDr(S, W, 1, 0x71374491);
|
||||
RNDr(S, W, 2, 0xb5c0fbcf);
|
||||
RNDr(S, W, 3, 0xe9b5dba5);
|
||||
RNDr(S, W, 4, 0x3956c25b);
|
||||
RNDr(S, W, 5, 0x59f111f1);
|
||||
RNDr(S, W, 6, 0x923f82a4);
|
||||
RNDr(S, W, 7, 0xab1c5ed5);
|
||||
RNDr(S, W, 8, 0xd807aa98);
|
||||
RNDr(S, W, 9, 0x12835b01);
|
||||
RNDr(S, W, 10, 0x243185be);
|
||||
RNDr(S, W, 11, 0x550c7dc3);
|
||||
RNDr(S, W, 12, 0x72be5d74);
|
||||
RNDr(S, W, 13, 0x80deb1fe);
|
||||
RNDr(S, W, 14, 0x9bdc06a7);
|
||||
RNDr(S, W, 15, 0xc19bf174);
|
||||
RNDr(S, W, 16, 0xe49b69c1);
|
||||
RNDr(S, W, 17, 0xefbe4786);
|
||||
RNDr(S, W, 18, 0x0fc19dc6);
|
||||
RNDr(S, W, 19, 0x240ca1cc);
|
||||
RNDr(S, W, 20, 0x2de92c6f);
|
||||
RNDr(S, W, 21, 0x4a7484aa);
|
||||
RNDr(S, W, 22, 0x5cb0a9dc);
|
||||
RNDr(S, W, 23, 0x76f988da);
|
||||
RNDr(S, W, 24, 0x983e5152);
|
||||
RNDr(S, W, 25, 0xa831c66d);
|
||||
RNDr(S, W, 26, 0xb00327c8);
|
||||
RNDr(S, W, 27, 0xbf597fc7);
|
||||
RNDr(S, W, 28, 0xc6e00bf3);
|
||||
RNDr(S, W, 29, 0xd5a79147);
|
||||
RNDr(S, W, 30, 0x06ca6351);
|
||||
RNDr(S, W, 31, 0x14292967);
|
||||
RNDr(S, W, 32, 0x27b70a85);
|
||||
RNDr(S, W, 33, 0x2e1b2138);
|
||||
RNDr(S, W, 34, 0x4d2c6dfc);
|
||||
RNDr(S, W, 35, 0x53380d13);
|
||||
RNDr(S, W, 36, 0x650a7354);
|
||||
RNDr(S, W, 37, 0x766a0abb);
|
||||
RNDr(S, W, 38, 0x81c2c92e);
|
||||
RNDr(S, W, 39, 0x92722c85);
|
||||
RNDr(S, W, 40, 0xa2bfe8a1);
|
||||
RNDr(S, W, 41, 0xa81a664b);
|
||||
RNDr(S, W, 42, 0xc24b8b70);
|
||||
RNDr(S, W, 43, 0xc76c51a3);
|
||||
RNDr(S, W, 44, 0xd192e819);
|
||||
RNDr(S, W, 45, 0xd6990624);
|
||||
RNDr(S, W, 46, 0xf40e3585);
|
||||
RNDr(S, W, 47, 0x106aa070);
|
||||
RNDr(S, W, 48, 0x19a4c116);
|
||||
RNDr(S, W, 49, 0x1e376c08);
|
||||
RNDr(S, W, 50, 0x2748774c);
|
||||
RNDr(S, W, 51, 0x34b0bcb5);
|
||||
RNDr(S, W, 52, 0x391c0cb3);
|
||||
RNDr(S, W, 53, 0x4ed8aa4a);
|
||||
RNDr(S, W, 54, 0x5b9cca4f);
|
||||
RNDr(S, W, 55, 0x682e6ff3);
|
||||
RNDr(S, W, 56, 0x748f82ee);
|
||||
RNDr(S, W, 57, 0x78a5636f);
|
||||
RNDr(S, W, 58, 0x84c87814);
|
||||
RNDr(S, W, 59, 0x8cc70208);
|
||||
RNDr(S, W, 60, 0x90befffa);
|
||||
RNDr(S, W, 61, 0xa4506ceb);
|
||||
RNDr(S, W, 62, 0xbef9a3f7);
|
||||
RNDr(S, W, 63, 0xc67178f2);
|
||||
|
||||
/* 4. Mix local working variables into global state */
|
||||
for (i = 0; i < 8; i++)
|
||||
state[i] += S[i];
|
||||
|
||||
/* Clean the stack. */
|
||||
memset(W, 0, 256);
|
||||
memset(S, 0, 32);
|
||||
t0 = t1 = 0;
|
||||
}
|
||||
|
||||
static unsigned char PAD[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/* SHA-256 initialization. Begins a SHA-256 operation. */
|
||||
static void
|
||||
SHA256_Init(SHA256_CTX * ctx)
|
||||
{
|
||||
|
||||
/* Zero bits processed so far */
|
||||
ctx->count[0] = ctx->count[1] = 0;
|
||||
|
||||
/* Magic initialization constants */
|
||||
ctx->state[0] = 0x6A09E667;
|
||||
ctx->state[1] = 0xBB67AE85;
|
||||
ctx->state[2] = 0x3C6EF372;
|
||||
ctx->state[3] = 0xA54FF53A;
|
||||
ctx->state[4] = 0x510E527F;
|
||||
ctx->state[5] = 0x9B05688C;
|
||||
ctx->state[6] = 0x1F83D9AB;
|
||||
ctx->state[7] = 0x5BE0CD19;
|
||||
}
|
||||
|
||||
/* Add bytes into the hash */
|
||||
static void
|
||||
SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len)
|
||||
{
|
||||
uint32_t bitlen[2];
|
||||
uint32_t r;
|
||||
const unsigned char *src = (const unsigned char *)in;
|
||||
|
||||
/* Number of bytes left in the buffer from previous updates */
|
||||
r = (ctx->count[1] >> 3) & 0x3f;
|
||||
|
||||
/* Convert the length into a number of bits */
|
||||
bitlen[1] = ((uint32_t)len) << 3;
|
||||
bitlen[0] = (uint32_t)(len >> 29);
|
||||
|
||||
/* Update number of bits */
|
||||
if ((ctx->count[1] += bitlen[1]) < bitlen[1])
|
||||
ctx->count[0]++;
|
||||
ctx->count[0] += bitlen[0];
|
||||
|
||||
/* Handle the case where we don't need to perform any transforms */
|
||||
if (len < 64 - r) {
|
||||
memcpy(&ctx->buf[r], src, len);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Finish the current block */
|
||||
memcpy(&ctx->buf[r], src, 64 - r);
|
||||
SHA256_Transform(ctx->state, ctx->buf);
|
||||
src += 64 - r;
|
||||
len -= 64 - r;
|
||||
|
||||
/* Perform complete blocks */
|
||||
while (len >= 64) {
|
||||
SHA256_Transform(ctx->state, src);
|
||||
src += 64;
|
||||
len -= 64;
|
||||
}
|
||||
|
||||
/* Copy left over data into buffer */
|
||||
memcpy(ctx->buf, src, len);
|
||||
}
|
||||
|
||||
/* Add padding and terminating bit-count. */
|
||||
static void
|
||||
SHA256_Pad(SHA256_CTX * ctx)
|
||||
{
|
||||
unsigned char len[8];
|
||||
uint32_t r, plen;
|
||||
|
||||
/*
|
||||
* Convert length to a vector of bytes -- we do this now rather
|
||||
* than later because the length will change after we pad.
|
||||
*/
|
||||
be32enc_vect(len, ctx->count, 8);
|
||||
|
||||
/* Add 1--64 bytes so that the resulting length is 56 mod 64 */
|
||||
r = (ctx->count[1] >> 3) & 0x3f;
|
||||
plen = (r < 56) ? (56 - r) : (120 - r);
|
||||
SHA256_Update(ctx, PAD, (size_t)plen);
|
||||
|
||||
/* Add the terminating bit-count */
|
||||
SHA256_Update(ctx, len, 8);
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-256 finalization. Pads the input data, exports the hash value,
|
||||
* and clears the context state.
|
||||
*/
|
||||
static void
|
||||
SHA256_Final(unsigned char digest[32], SHA256_CTX * ctx)
|
||||
{
|
||||
|
||||
/* Add padding */
|
||||
SHA256_Pad(ctx);
|
||||
|
||||
/* Write the hash */
|
||||
be32enc_vect(digest, ctx->state, 32);
|
||||
|
||||
/* Clear the context state */
|
||||
memset((void *)ctx, 0, sizeof(*ctx));
|
||||
}
|
||||
|
||||
/* Initialize an HMAC-SHA256 operation with the given key. */
|
||||
static void
|
||||
HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen)
|
||||
{
|
||||
unsigned char pad[64];
|
||||
unsigned char khash[32];
|
||||
const unsigned char * K = (const unsigned char *)_K;
|
||||
size_t i;
|
||||
|
||||
/* If Klen > 64, the key is really SHA256(K). */
|
||||
if (Klen > 64) {
|
||||
SHA256_Init(&ctx->ictx);
|
||||
SHA256_Update(&ctx->ictx, K, Klen);
|
||||
SHA256_Final(khash, &ctx->ictx);
|
||||
K = khash;
|
||||
Klen = 32;
|
||||
}
|
||||
|
||||
/* Inner SHA256 operation is SHA256(K xor [block of 0x36] || data). */
|
||||
SHA256_Init(&ctx->ictx);
|
||||
memset(pad, 0x36, 64);
|
||||
for (i = 0; i < Klen; i++)
|
||||
pad[i] ^= K[i];
|
||||
SHA256_Update(&ctx->ictx, pad, 64);
|
||||
|
||||
/* Outer SHA256 operation is SHA256(K xor [block of 0x5c] || hash). */
|
||||
SHA256_Init(&ctx->octx);
|
||||
memset(pad, 0x5c, 64);
|
||||
for (i = 0; i < Klen; i++)
|
||||
pad[i] ^= K[i];
|
||||
SHA256_Update(&ctx->octx, pad, 64);
|
||||
|
||||
/* Clean the stack. */
|
||||
memset(khash, 0, 32);
|
||||
}
|
||||
|
||||
/* Add bytes to the HMAC-SHA256 operation. */
|
||||
static void
|
||||
HMAC_SHA256_Update(HMAC_SHA256_CTX * ctx, const void *in, size_t len)
|
||||
{
|
||||
|
||||
/* Feed data to the inner SHA256 operation. */
|
||||
SHA256_Update(&ctx->ictx, in, len);
|
||||
}
|
||||
|
||||
/* Finish an HMAC-SHA256 operation. */
|
||||
static void
|
||||
HMAC_SHA256_Final(unsigned char digest[32], HMAC_SHA256_CTX * ctx)
|
||||
{
|
||||
unsigned char ihash[32];
|
||||
|
||||
/* Finish the inner SHA256 operation. */
|
||||
SHA256_Final(ihash, &ctx->ictx);
|
||||
|
||||
/* Feed the inner hash to the outer SHA256 operation. */
|
||||
SHA256_Update(&ctx->octx, ihash, 32);
|
||||
|
||||
/* Finish the outer SHA256 operation. */
|
||||
SHA256_Final(digest, &ctx->octx);
|
||||
|
||||
/* Clean the stack. */
|
||||
memset(ihash, 0, 32);
|
||||
}
|
||||
|
||||
/**
|
||||
* PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen):
|
||||
* Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and
|
||||
* write the output to buf. The value dkLen must be at most 32 * (2^32 - 1).
|
||||
*/
|
||||
static void
|
||||
PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt,
|
||||
size_t saltlen, uint64_t c, uint8_t * buf, size_t dkLen)
|
||||
{
|
||||
HMAC_SHA256_CTX PShctx, hctx;
|
||||
size_t i;
|
||||
uint8_t ivec[4];
|
||||
uint8_t U[32];
|
||||
uint8_t T[32];
|
||||
uint64_t j;
|
||||
int k;
|
||||
size_t clen;
|
||||
|
||||
/* Compute HMAC state after processing P and S. */
|
||||
HMAC_SHA256_Init(&PShctx, passwd, passwdlen);
|
||||
HMAC_SHA256_Update(&PShctx, salt, saltlen);
|
||||
|
||||
/* Iterate through the blocks. */
|
||||
for (i = 0; i * 32 < dkLen; i++) {
|
||||
/* Generate INT(i + 1). */
|
||||
be32enc(ivec, (uint32_t)(i + 1));
|
||||
|
||||
/* Compute U_1 = PRF(P, S || INT(i)). */
|
||||
memcpy(&hctx, &PShctx, sizeof(HMAC_SHA256_CTX));
|
||||
HMAC_SHA256_Update(&hctx, ivec, 4);
|
||||
HMAC_SHA256_Final(U, &hctx);
|
||||
|
||||
/* T_i = U_1 ... */
|
||||
memcpy(T, U, 32);
|
||||
|
||||
for (j = 2; j <= c; j++) {
|
||||
/* Compute U_j. */
|
||||
HMAC_SHA256_Init(&hctx, passwd, passwdlen);
|
||||
HMAC_SHA256_Update(&hctx, U, 32);
|
||||
HMAC_SHA256_Final(U, &hctx);
|
||||
|
||||
/* ... xor U_j ... */
|
||||
for (k = 0; k < 32; k++)
|
||||
T[k] ^= U[k];
|
||||
}
|
||||
|
||||
/* Copy as many bytes as necessary into buf. */
|
||||
clen = dkLen - i * 32;
|
||||
if (clen > 32)
|
||||
clen = 32;
|
||||
memcpy(&buf[i * 32], T, clen);
|
||||
}
|
||||
|
||||
/* Clean PShctx, since we never called _Final on it. */
|
||||
memset(&PShctx, 0, sizeof(HMAC_SHA256_CTX));
|
||||
}
|
||||
#endif
|
||||
#ifndef SHA256_H
|
||||
#define SHA256_H
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
#include "stdint.h"
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
static __inline uint32_t
|
||||
be32dec(const void *pp)
|
||||
{
|
||||
const uint8_t *p = (uint8_t const *)pp;
|
||||
|
||||
return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) +
|
||||
((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
|
||||
}
|
||||
|
||||
static __inline void
|
||||
be32enc(void *pp, uint32_t x)
|
||||
{
|
||||
uint8_t * p = (uint8_t *)pp;
|
||||
|
||||
p[3] = x & 0xff;
|
||||
p[2] = (x >> 8) & 0xff;
|
||||
p[1] = (x >> 16) & 0xff;
|
||||
p[0] = (x >> 24) & 0xff;
|
||||
}
|
||||
|
||||
static __inline uint32_t
|
||||
le32dec(const void *pp)
|
||||
{
|
||||
const uint8_t *p = (uint8_t const *)pp;
|
||||
|
||||
return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) +
|
||||
((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
|
||||
}
|
||||
|
||||
static __inline void
|
||||
le32enc(void *pp, uint32_t x)
|
||||
{
|
||||
uint8_t * p = (uint8_t *)pp;
|
||||
|
||||
p[0] = x & 0xff;
|
||||
p[1] = (x >> 8) & 0xff;
|
||||
p[2] = (x >> 16) & 0xff;
|
||||
p[3] = (x >> 24) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
typedef struct SHA256Context {
|
||||
uint32_t state[8];
|
||||
uint32_t count[2];
|
||||
unsigned char buf[64];
|
||||
} SHA256_CTX;
|
||||
|
||||
typedef struct HMAC_SHA256Context {
|
||||
SHA256_CTX ictx;
|
||||
SHA256_CTX octx;
|
||||
} HMAC_SHA256_CTX;
|
||||
|
||||
/*
|
||||
* Encode a length len/4 vector of (uint32_t) into a length len vector of
|
||||
* (unsigned char) in big-endian form. Assumes len is a multiple of 4.
|
||||
*/
|
||||
static void
|
||||
be32enc_vect(unsigned char *dst, const uint32_t *src, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len / 4; i++)
|
||||
be32enc(dst + i * 4, src[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Decode a big-endian length len vector of (unsigned char) into a length
|
||||
* len/4 vector of (uint32_t). Assumes len is a multiple of 4.
|
||||
*/
|
||||
static void
|
||||
be32dec_vect(uint32_t *dst, const unsigned char *src, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < len / 4; i++)
|
||||
dst[i] = be32dec(src + i * 4);
|
||||
}
|
||||
|
||||
/* Elementary functions used by SHA256 */
|
||||
#define Ch(x, y, z) ((x & (y ^ z)) ^ z)
|
||||
#define Maj(x, y, z) ((x & (y | z)) | (y & z))
|
||||
#define SHR(x, n) (x >> n)
|
||||
#define ROTR(x, n) ((x >> n) | (x << (32 - n)))
|
||||
#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
|
||||
#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
|
||||
#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3))
|
||||
#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10))
|
||||
|
||||
/* SHA256 round function */
|
||||
#define RND(a, b, c, d, e, f, g, h, k) \
|
||||
t0 = h + S1(e) + Ch(e, f, g) + k; \
|
||||
t1 = S0(a) + Maj(a, b, c); \
|
||||
d += t0; \
|
||||
h = t0 + t1;
|
||||
|
||||
/* Adjusted round function for rotating state */
|
||||
#define RNDr(S, W, i, k) \
|
||||
RND(S[(64 - i) % 8], S[(65 - i) % 8], \
|
||||
S[(66 - i) % 8], S[(67 - i) % 8], \
|
||||
S[(68 - i) % 8], S[(69 - i) % 8], \
|
||||
S[(70 - i) % 8], S[(71 - i) % 8], \
|
||||
W[i] + k)
|
||||
|
||||
/*
|
||||
* SHA256 block compression function. The 256-bit state is transformed via
|
||||
* the 512-bit input block to produce a new state.
|
||||
*/
|
||||
static void
|
||||
SHA256_Transform(uint32_t * state, const unsigned char block[64])
|
||||
{
|
||||
uint32_t W[64];
|
||||
uint32_t S[8];
|
||||
uint32_t t0, t1;
|
||||
int i;
|
||||
|
||||
/* 1. Prepare message schedule W. */
|
||||
be32dec_vect(W, block, 64);
|
||||
for (i = 16; i < 64; i++)
|
||||
W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16];
|
||||
|
||||
/* 2. Initialize working variables. */
|
||||
memcpy(S, state, 32);
|
||||
|
||||
/* 3. Mix. */
|
||||
RNDr(S, W, 0, 0x428a2f98);
|
||||
RNDr(S, W, 1, 0x71374491);
|
||||
RNDr(S, W, 2, 0xb5c0fbcf);
|
||||
RNDr(S, W, 3, 0xe9b5dba5);
|
||||
RNDr(S, W, 4, 0x3956c25b);
|
||||
RNDr(S, W, 5, 0x59f111f1);
|
||||
RNDr(S, W, 6, 0x923f82a4);
|
||||
RNDr(S, W, 7, 0xab1c5ed5);
|
||||
RNDr(S, W, 8, 0xd807aa98);
|
||||
RNDr(S, W, 9, 0x12835b01);
|
||||
RNDr(S, W, 10, 0x243185be);
|
||||
RNDr(S, W, 11, 0x550c7dc3);
|
||||
RNDr(S, W, 12, 0x72be5d74);
|
||||
RNDr(S, W, 13, 0x80deb1fe);
|
||||
RNDr(S, W, 14, 0x9bdc06a7);
|
||||
RNDr(S, W, 15, 0xc19bf174);
|
||||
RNDr(S, W, 16, 0xe49b69c1);
|
||||
RNDr(S, W, 17, 0xefbe4786);
|
||||
RNDr(S, W, 18, 0x0fc19dc6);
|
||||
RNDr(S, W, 19, 0x240ca1cc);
|
||||
RNDr(S, W, 20, 0x2de92c6f);
|
||||
RNDr(S, W, 21, 0x4a7484aa);
|
||||
RNDr(S, W, 22, 0x5cb0a9dc);
|
||||
RNDr(S, W, 23, 0x76f988da);
|
||||
RNDr(S, W, 24, 0x983e5152);
|
||||
RNDr(S, W, 25, 0xa831c66d);
|
||||
RNDr(S, W, 26, 0xb00327c8);
|
||||
RNDr(S, W, 27, 0xbf597fc7);
|
||||
RNDr(S, W, 28, 0xc6e00bf3);
|
||||
RNDr(S, W, 29, 0xd5a79147);
|
||||
RNDr(S, W, 30, 0x06ca6351);
|
||||
RNDr(S, W, 31, 0x14292967);
|
||||
RNDr(S, W, 32, 0x27b70a85);
|
||||
RNDr(S, W, 33, 0x2e1b2138);
|
||||
RNDr(S, W, 34, 0x4d2c6dfc);
|
||||
RNDr(S, W, 35, 0x53380d13);
|
||||
RNDr(S, W, 36, 0x650a7354);
|
||||
RNDr(S, W, 37, 0x766a0abb);
|
||||
RNDr(S, W, 38, 0x81c2c92e);
|
||||
RNDr(S, W, 39, 0x92722c85);
|
||||
RNDr(S, W, 40, 0xa2bfe8a1);
|
||||
RNDr(S, W, 41, 0xa81a664b);
|
||||
RNDr(S, W, 42, 0xc24b8b70);
|
||||
RNDr(S, W, 43, 0xc76c51a3);
|
||||
RNDr(S, W, 44, 0xd192e819);
|
||||
RNDr(S, W, 45, 0xd6990624);
|
||||
RNDr(S, W, 46, 0xf40e3585);
|
||||
RNDr(S, W, 47, 0x106aa070);
|
||||
RNDr(S, W, 48, 0x19a4c116);
|
||||
RNDr(S, W, 49, 0x1e376c08);
|
||||
RNDr(S, W, 50, 0x2748774c);
|
||||
RNDr(S, W, 51, 0x34b0bcb5);
|
||||
RNDr(S, W, 52, 0x391c0cb3);
|
||||
RNDr(S, W, 53, 0x4ed8aa4a);
|
||||
RNDr(S, W, 54, 0x5b9cca4f);
|
||||
RNDr(S, W, 55, 0x682e6ff3);
|
||||
RNDr(S, W, 56, 0x748f82ee);
|
||||
RNDr(S, W, 57, 0x78a5636f);
|
||||
RNDr(S, W, 58, 0x84c87814);
|
||||
RNDr(S, W, 59, 0x8cc70208);
|
||||
RNDr(S, W, 60, 0x90befffa);
|
||||
RNDr(S, W, 61, 0xa4506ceb);
|
||||
RNDr(S, W, 62, 0xbef9a3f7);
|
||||
RNDr(S, W, 63, 0xc67178f2);
|
||||
|
||||
/* 4. Mix local working variables into global state */
|
||||
for (i = 0; i < 8; i++)
|
||||
state[i] += S[i];
|
||||
|
||||
/* Clean the stack. */
|
||||
memset(W, 0, 256);
|
||||
memset(S, 0, 32);
|
||||
t0 = t1 = 0;
|
||||
}
|
||||
|
||||
static unsigned char PAD[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/* SHA-256 initialization. Begins a SHA-256 operation. */
|
||||
static void
|
||||
SHA256_Init(SHA256_CTX * ctx)
|
||||
{
|
||||
|
||||
/* Zero bits processed so far */
|
||||
ctx->count[0] = ctx->count[1] = 0;
|
||||
|
||||
/* Magic initialization constants */
|
||||
ctx->state[0] = 0x6A09E667;
|
||||
ctx->state[1] = 0xBB67AE85;
|
||||
ctx->state[2] = 0x3C6EF372;
|
||||
ctx->state[3] = 0xA54FF53A;
|
||||
ctx->state[4] = 0x510E527F;
|
||||
ctx->state[5] = 0x9B05688C;
|
||||
ctx->state[6] = 0x1F83D9AB;
|
||||
ctx->state[7] = 0x5BE0CD19;
|
||||
}
|
||||
|
||||
/* Add bytes into the hash */
|
||||
static void
|
||||
SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len)
|
||||
{
|
||||
uint32_t bitlen[2];
|
||||
uint32_t r;
|
||||
const unsigned char *src = (const unsigned char *)in;
|
||||
|
||||
/* Number of bytes left in the buffer from previous updates */
|
||||
r = (ctx->count[1] >> 3) & 0x3f;
|
||||
|
||||
/* Convert the length into a number of bits */
|
||||
bitlen[1] = ((uint32_t)len) << 3;
|
||||
bitlen[0] = (uint32_t)(len >> 29);
|
||||
|
||||
/* Update number of bits */
|
||||
if ((ctx->count[1] += bitlen[1]) < bitlen[1])
|
||||
ctx->count[0]++;
|
||||
ctx->count[0] += bitlen[0];
|
||||
|
||||
/* Handle the case where we don't need to perform any transforms */
|
||||
if (len < 64 - r) {
|
||||
memcpy(&ctx->buf[r], src, len);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Finish the current block */
|
||||
memcpy(&ctx->buf[r], src, 64 - r);
|
||||
SHA256_Transform(ctx->state, ctx->buf);
|
||||
src += 64 - r;
|
||||
len -= 64 - r;
|
||||
|
||||
/* Perform complete blocks */
|
||||
while (len >= 64) {
|
||||
SHA256_Transform(ctx->state, src);
|
||||
src += 64;
|
||||
len -= 64;
|
||||
}
|
||||
|
||||
/* Copy left over data into buffer */
|
||||
memcpy(ctx->buf, src, len);
|
||||
}
|
||||
|
||||
/* Add padding and terminating bit-count. */
|
||||
static void
|
||||
SHA256_Pad(SHA256_CTX * ctx)
|
||||
{
|
||||
unsigned char len[8];
|
||||
uint32_t r, plen;
|
||||
|
||||
/*
|
||||
* Convert length to a vector of bytes -- we do this now rather
|
||||
* than later because the length will change after we pad.
|
||||
*/
|
||||
be32enc_vect(len, ctx->count, 8);
|
||||
|
||||
/* Add 1--64 bytes so that the resulting length is 56 mod 64 */
|
||||
r = (ctx->count[1] >> 3) & 0x3f;
|
||||
plen = (r < 56) ? (56 - r) : (120 - r);
|
||||
SHA256_Update(ctx, PAD, (size_t)plen);
|
||||
|
||||
/* Add the terminating bit-count */
|
||||
SHA256_Update(ctx, len, 8);
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-256 finalization. Pads the input data, exports the hash value,
|
||||
* and clears the context state.
|
||||
*/
|
||||
static void
|
||||
SHA256_Final(unsigned char digest[32], SHA256_CTX * ctx)
|
||||
{
|
||||
|
||||
/* Add padding */
|
||||
SHA256_Pad(ctx);
|
||||
|
||||
/* Write the hash */
|
||||
be32enc_vect(digest, ctx->state, 32);
|
||||
|
||||
/* Clear the context state */
|
||||
memset((void *)ctx, 0, sizeof(*ctx));
|
||||
}
|
||||
|
||||
/* Initialize an HMAC-SHA256 operation with the given key. */
|
||||
static void
|
||||
HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen)
|
||||
{
|
||||
unsigned char pad[64];
|
||||
unsigned char khash[32];
|
||||
const unsigned char * K = (const unsigned char *)_K;
|
||||
size_t i;
|
||||
|
||||
/* If Klen > 64, the key is really SHA256(K). */
|
||||
if (Klen > 64) {
|
||||
SHA256_Init(&ctx->ictx);
|
||||
SHA256_Update(&ctx->ictx, K, Klen);
|
||||
SHA256_Final(khash, &ctx->ictx);
|
||||
K = khash;
|
||||
Klen = 32;
|
||||
}
|
||||
|
||||
/* Inner SHA256 operation is SHA256(K xor [block of 0x36] || data). */
|
||||
SHA256_Init(&ctx->ictx);
|
||||
memset(pad, 0x36, 64);
|
||||
for (i = 0; i < Klen; i++)
|
||||
pad[i] ^= K[i];
|
||||
SHA256_Update(&ctx->ictx, pad, 64);
|
||||
|
||||
/* Outer SHA256 operation is SHA256(K xor [block of 0x5c] || hash). */
|
||||
SHA256_Init(&ctx->octx);
|
||||
memset(pad, 0x5c, 64);
|
||||
for (i = 0; i < Klen; i++)
|
||||
pad[i] ^= K[i];
|
||||
SHA256_Update(&ctx->octx, pad, 64);
|
||||
|
||||
/* Clean the stack. */
|
||||
memset(khash, 0, 32);
|
||||
}
|
||||
|
||||
/* Add bytes to the HMAC-SHA256 operation. */
|
||||
static void
|
||||
HMAC_SHA256_Update(HMAC_SHA256_CTX * ctx, const void *in, size_t len)
|
||||
{
|
||||
|
||||
/* Feed data to the inner SHA256 operation. */
|
||||
SHA256_Update(&ctx->ictx, in, len);
|
||||
}
|
||||
|
||||
/* Finish an HMAC-SHA256 operation. */
|
||||
static void
|
||||
HMAC_SHA256_Final(unsigned char digest[32], HMAC_SHA256_CTX * ctx)
|
||||
{
|
||||
unsigned char ihash[32];
|
||||
|
||||
/* Finish the inner SHA256 operation. */
|
||||
SHA256_Final(ihash, &ctx->ictx);
|
||||
|
||||
/* Feed the inner hash to the outer SHA256 operation. */
|
||||
SHA256_Update(&ctx->octx, ihash, 32);
|
||||
|
||||
/* Finish the outer SHA256 operation. */
|
||||
SHA256_Final(digest, &ctx->octx);
|
||||
|
||||
/* Clean the stack. */
|
||||
memset(ihash, 0, 32);
|
||||
}
|
||||
|
||||
/**
|
||||
* PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen):
|
||||
* Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and
|
||||
* write the output to buf. The value dkLen must be at most 32 * (2^32 - 1).
|
||||
*/
|
||||
static void
|
||||
PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt,
|
||||
size_t saltlen, uint64_t c, uint8_t * buf, size_t dkLen)
|
||||
{
|
||||
HMAC_SHA256_CTX PShctx, hctx;
|
||||
size_t i;
|
||||
uint8_t ivec[4];
|
||||
uint8_t U[32];
|
||||
uint8_t T[32];
|
||||
uint64_t j;
|
||||
int k;
|
||||
size_t clen;
|
||||
|
||||
/* Compute HMAC state after processing P and S. */
|
||||
HMAC_SHA256_Init(&PShctx, passwd, passwdlen);
|
||||
HMAC_SHA256_Update(&PShctx, salt, saltlen);
|
||||
|
||||
/* Iterate through the blocks. */
|
||||
for (i = 0; i * 32 < dkLen; i++) {
|
||||
/* Generate INT(i + 1). */
|
||||
be32enc(ivec, (uint32_t)(i + 1));
|
||||
|
||||
/* Compute U_1 = PRF(P, S || INT(i)). */
|
||||
memcpy(&hctx, &PShctx, sizeof(HMAC_SHA256_CTX));
|
||||
HMAC_SHA256_Update(&hctx, ivec, 4);
|
||||
HMAC_SHA256_Final(U, &hctx);
|
||||
|
||||
/* T_i = U_1 ... */
|
||||
memcpy(T, U, 32);
|
||||
|
||||
for (j = 2; j <= c; j++) {
|
||||
/* Compute U_j. */
|
||||
HMAC_SHA256_Init(&hctx, passwd, passwdlen);
|
||||
HMAC_SHA256_Update(&hctx, U, 32);
|
||||
HMAC_SHA256_Final(U, &hctx);
|
||||
|
||||
/* ... xor U_j ... */
|
||||
for (k = 0; k < 32; k++)
|
||||
T[k] ^= U[k];
|
||||
}
|
||||
|
||||
/* Copy as many bytes as necessary into buf. */
|
||||
clen = dkLen - i * 32;
|
||||
if (clen > 32)
|
||||
clen = 32;
|
||||
memcpy(&buf[i * 32], T, clen);
|
||||
}
|
||||
|
||||
/* Clean PShctx, since we never called _Final on it. */
|
||||
memset(&PShctx, 0, sizeof(HMAC_SHA256_CTX));
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
|
||||
#include "skein.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_skein.h"
|
||||
#include "sha256.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void skein_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
char temp[64];
|
||||
|
||||
sph_skein512_context ctx_skien;
|
||||
sph_skein512_init(&ctx_skien);
|
||||
sph_skein512(&ctx_skien, input, len);
|
||||
sph_skein512_close(&ctx_skien, &temp);
|
||||
|
||||
SHA256_CTX ctx_sha256;
|
||||
SHA256_Init(&ctx_sha256);
|
||||
SHA256_Update(&ctx_sha256, &temp, 64);
|
||||
SHA256_Final((unsigned char*) output, &ctx_sha256);
|
||||
}
|
||||
|
||||
|
||||
#include "skein.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_skein.h"
|
||||
#include "sha256.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void skein_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
char temp[64];
|
||||
|
||||
sph_skein512_context ctx_skien;
|
||||
sph_skein512_init(&ctx_skien);
|
||||
sph_skein512(&ctx_skien, input, len);
|
||||
sph_skein512_close(&ctx_skien, &temp);
|
||||
|
||||
SHA256_CTX ctx_sha256;
|
||||
SHA256_Init(&ctx_sha256);
|
||||
SHA256_Update(&ctx_sha256, &temp, 64);
|
||||
SHA256_Final((unsigned char*) output, &ctx_sha256);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#ifndef SKEIN_H
|
||||
#define SKEIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void skein_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#ifndef SKEIN_H
|
||||
#define SKEIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void skein_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,98 +1,98 @@
|
|||
#include "x13.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_blake.h"
|
||||
#include "../sha3/sph_bmw.h"
|
||||
#include "../sha3/sph_groestl.h"
|
||||
#include "../sha3/sph_jh.h"
|
||||
#include "../sha3/sph_keccak.h"
|
||||
#include "../sha3/sph_skein.h"
|
||||
#include "../sha3/sph_luffa.h"
|
||||
#include "../sha3/sph_cubehash.h"
|
||||
#include "../sha3/sph_shavite.h"
|
||||
#include "../sha3/sph_simd.h"
|
||||
#include "../sha3/sph_echo.h"
|
||||
#include "../sha3/sph_hamsi.h"
|
||||
#include "../sha3/sph_fugue.h"
|
||||
|
||||
|
||||
void x13_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_bmw512_context ctx_bmw;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_skein512_context ctx_skein;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_luffa512_context ctx_luffa1;
|
||||
sph_cubehash512_context ctx_cubehash1;
|
||||
sph_shavite512_context ctx_shavite1;
|
||||
sph_simd512_context ctx_simd1;
|
||||
sph_echo512_context ctx_echo1;
|
||||
sph_hamsi512_context ctx_hamsi1;
|
||||
sph_fugue512_context ctx_fugue1;
|
||||
|
||||
//these uint512 in the c++ source of the client are backed by an array of uint32
|
||||
uint32_t hashA[16], hashB[16];
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, input, len);
|
||||
sph_blake512_close (&ctx_blake, hashA);
|
||||
|
||||
sph_bmw512_init(&ctx_bmw);
|
||||
sph_bmw512 (&ctx_bmw, hashA, 64);
|
||||
sph_bmw512_close(&ctx_bmw, hashB);
|
||||
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, hashB, 64);
|
||||
sph_groestl512_close(&ctx_groestl, hashA);
|
||||
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512 (&ctx_skein, hashA, 64);
|
||||
sph_skein512_close (&ctx_skein, hashB);
|
||||
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512 (&ctx_jh, hashB, 64);
|
||||
sph_jh512_close(&ctx_jh, hashA);
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak, hashA, 64);
|
||||
sph_keccak512_close(&ctx_keccak, hashB);
|
||||
|
||||
sph_luffa512_init (&ctx_luffa1);
|
||||
sph_luffa512 (&ctx_luffa1, hashB, 64);
|
||||
sph_luffa512_close (&ctx_luffa1, hashA);
|
||||
|
||||
sph_cubehash512_init (&ctx_cubehash1);
|
||||
sph_cubehash512 (&ctx_cubehash1, hashA, 64);
|
||||
sph_cubehash512_close(&ctx_cubehash1, hashB);
|
||||
|
||||
sph_shavite512_init (&ctx_shavite1);
|
||||
sph_shavite512 (&ctx_shavite1, hashB, 64);
|
||||
sph_shavite512_close(&ctx_shavite1, hashA);
|
||||
|
||||
sph_simd512_init (&ctx_simd1);
|
||||
sph_simd512 (&ctx_simd1, hashA, 64);
|
||||
sph_simd512_close(&ctx_simd1, hashB);
|
||||
|
||||
sph_echo512_init (&ctx_echo1);
|
||||
sph_echo512 (&ctx_echo1, hashB, 64);
|
||||
sph_echo512_close(&ctx_echo1, hashA);
|
||||
|
||||
sph_hamsi512_init (&ctx_hamsi1);
|
||||
sph_hamsi512 (&ctx_hamsi1, hashA, 64);
|
||||
sph_hamsi512_close(&ctx_hamsi1, hashB);
|
||||
|
||||
sph_fugue512_init (&ctx_fugue1);
|
||||
sph_fugue512 (&ctx_fugue1, hashB, 64);
|
||||
sph_fugue512_close(&ctx_fugue1, hashA);
|
||||
|
||||
|
||||
|
||||
memcpy(output, hashA, 32);
|
||||
|
||||
}
|
||||
|
||||
#include "x13.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_blake.h"
|
||||
#include "../sha3/sph_bmw.h"
|
||||
#include "../sha3/sph_groestl.h"
|
||||
#include "../sha3/sph_jh.h"
|
||||
#include "../sha3/sph_keccak.h"
|
||||
#include "../sha3/sph_skein.h"
|
||||
#include "../sha3/sph_luffa.h"
|
||||
#include "../sha3/sph_cubehash.h"
|
||||
#include "../sha3/sph_shavite.h"
|
||||
#include "../sha3/sph_simd.h"
|
||||
#include "../sha3/sph_echo.h"
|
||||
#include "../sha3/sph_hamsi.h"
|
||||
#include "../sha3/sph_fugue.h"
|
||||
|
||||
|
||||
void x13_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_bmw512_context ctx_bmw;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_skein512_context ctx_skein;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_luffa512_context ctx_luffa1;
|
||||
sph_cubehash512_context ctx_cubehash1;
|
||||
sph_shavite512_context ctx_shavite1;
|
||||
sph_simd512_context ctx_simd1;
|
||||
sph_echo512_context ctx_echo1;
|
||||
sph_hamsi512_context ctx_hamsi1;
|
||||
sph_fugue512_context ctx_fugue1;
|
||||
|
||||
//these uint512 in the c++ source of the client are backed by an array of uint32
|
||||
uint32_t hashA[16], hashB[16];
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, input, len);
|
||||
sph_blake512_close (&ctx_blake, hashA);
|
||||
|
||||
sph_bmw512_init(&ctx_bmw);
|
||||
sph_bmw512 (&ctx_bmw, hashA, 64);
|
||||
sph_bmw512_close(&ctx_bmw, hashB);
|
||||
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, hashB, 64);
|
||||
sph_groestl512_close(&ctx_groestl, hashA);
|
||||
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512 (&ctx_skein, hashA, 64);
|
||||
sph_skein512_close (&ctx_skein, hashB);
|
||||
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512 (&ctx_jh, hashB, 64);
|
||||
sph_jh512_close(&ctx_jh, hashA);
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak, hashA, 64);
|
||||
sph_keccak512_close(&ctx_keccak, hashB);
|
||||
|
||||
sph_luffa512_init (&ctx_luffa1);
|
||||
sph_luffa512 (&ctx_luffa1, hashB, 64);
|
||||
sph_luffa512_close (&ctx_luffa1, hashA);
|
||||
|
||||
sph_cubehash512_init (&ctx_cubehash1);
|
||||
sph_cubehash512 (&ctx_cubehash1, hashA, 64);
|
||||
sph_cubehash512_close(&ctx_cubehash1, hashB);
|
||||
|
||||
sph_shavite512_init (&ctx_shavite1);
|
||||
sph_shavite512 (&ctx_shavite1, hashB, 64);
|
||||
sph_shavite512_close(&ctx_shavite1, hashA);
|
||||
|
||||
sph_simd512_init (&ctx_simd1);
|
||||
sph_simd512 (&ctx_simd1, hashA, 64);
|
||||
sph_simd512_close(&ctx_simd1, hashB);
|
||||
|
||||
sph_echo512_init (&ctx_echo1);
|
||||
sph_echo512 (&ctx_echo1, hashB, 64);
|
||||
sph_echo512_close(&ctx_echo1, hashA);
|
||||
|
||||
sph_hamsi512_init (&ctx_hamsi1);
|
||||
sph_hamsi512 (&ctx_hamsi1, hashA, 64);
|
||||
sph_hamsi512_close(&ctx_hamsi1, hashB);
|
||||
|
||||
sph_fugue512_init (&ctx_fugue1);
|
||||
sph_fugue512 (&ctx_fugue1, hashB, 64);
|
||||
sph_fugue512_close(&ctx_fugue1, hashA);
|
||||
|
||||
|
||||
|
||||
memcpy(output, hashA, 32);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#ifndef X13_H
|
||||
#define X13_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void x13_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#ifndef X13_H
|
||||
#define X13_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void x13_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,104 +1,104 @@
|
|||
#include "x15.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_blake.h"
|
||||
#include "../sha3/sph_groestl.h"
|
||||
#include "../sha3/sph_jh.h"
|
||||
#include "../sha3/sph_keccak.h"
|
||||
#include "../sha3/sph_skein.h"
|
||||
|
||||
#define ZR_BLAKE 0
|
||||
#define ZR_GROESTL 1
|
||||
#define ZR_JH 2
|
||||
#define ZR_SKEIN 3
|
||||
|
||||
#define POK_BOOL_MASK 0x00008000
|
||||
#define POK_DATA_MASK 0xFFFF0000
|
||||
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
static const int permut[][4] = {
|
||||
{0, 1, 2, 3},
|
||||
{0, 1, 3, 2},
|
||||
{0, 2, 1, 3},
|
||||
{0, 2, 3, 1},
|
||||
{0, 3, 1, 2},
|
||||
{0, 3, 2, 1},
|
||||
{1, 0, 2, 3},
|
||||
{1, 0, 3, 2},
|
||||
{1, 2, 0, 3},
|
||||
{1, 2, 3, 0},
|
||||
{1, 3, 0, 2},
|
||||
{1, 3, 2, 0},
|
||||
{2, 0, 1, 3},
|
||||
{2, 0, 3, 1},
|
||||
{2, 1, 0, 3},
|
||||
{2, 1, 3, 0},
|
||||
{2, 3, 0, 1},
|
||||
{2, 3, 1, 0},
|
||||
{3, 0, 1, 2},
|
||||
{3, 0, 2, 1},
|
||||
{3, 1, 0, 2},
|
||||
{3, 1, 2, 0},
|
||||
{3, 2, 0, 1},
|
||||
{3, 2, 1, 0}
|
||||
};
|
||||
|
||||
void zr5_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_skein512_context ctx_skein;
|
||||
|
||||
uint32_t hash[5][16];
|
||||
char *ph = (char *)hash;
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512(&ctx_keccak, (const void*) input, len);
|
||||
sph_keccak512_close(&ctx_keccak, (void*) &hash[0][0]);
|
||||
|
||||
unsigned int norder = hash[0][0] % ARRAY_SIZE(permut); /* % 24 */
|
||||
int i;
|
||||
|
||||
for(i=0; i<len; i++) printf("%02x", (unsigned char)input[i]); printf("\n");
|
||||
for(i=0; i<32; i++) printf("%02x", (unsigned char)ph[i]); printf("\n");
|
||||
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
void* phash = (void*) &(hash[i][0]);
|
||||
void* pdest = (void*) &(hash[i+1][0]);
|
||||
|
||||
printf("permut %d\n", permut[norder][i]);
|
||||
switch (permut[norder][i]) {
|
||||
case ZR_BLAKE:
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512(&ctx_blake, (const void*) phash, 64);
|
||||
sph_blake512_close(&ctx_blake, pdest);
|
||||
break;
|
||||
case ZR_GROESTL:
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512(&ctx_groestl, (const void*) phash, 64);
|
||||
sph_groestl512_close(&ctx_groestl, pdest);
|
||||
break;
|
||||
case ZR_JH:
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512(&ctx_jh, (const void*) phash, 64);
|
||||
sph_jh512_close(&ctx_jh, pdest);
|
||||
break;
|
||||
case ZR_SKEIN:
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512(&ctx_skein, (const void*) phash, 64);
|
||||
sph_skein512_close(&ctx_skein, pdest);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
memcpy(output, &hash[4], 32);
|
||||
}
|
||||
|
||||
#include "x15.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../sha3/sph_blake.h"
|
||||
#include "../sha3/sph_groestl.h"
|
||||
#include "../sha3/sph_jh.h"
|
||||
#include "../sha3/sph_keccak.h"
|
||||
#include "../sha3/sph_skein.h"
|
||||
|
||||
#define ZR_BLAKE 0
|
||||
#define ZR_GROESTL 1
|
||||
#define ZR_JH 2
|
||||
#define ZR_SKEIN 3
|
||||
|
||||
#define POK_BOOL_MASK 0x00008000
|
||||
#define POK_DATA_MASK 0xFFFF0000
|
||||
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
static const int permut[][4] = {
|
||||
{0, 1, 2, 3},
|
||||
{0, 1, 3, 2},
|
||||
{0, 2, 1, 3},
|
||||
{0, 2, 3, 1},
|
||||
{0, 3, 1, 2},
|
||||
{0, 3, 2, 1},
|
||||
{1, 0, 2, 3},
|
||||
{1, 0, 3, 2},
|
||||
{1, 2, 0, 3},
|
||||
{1, 2, 3, 0},
|
||||
{1, 3, 0, 2},
|
||||
{1, 3, 2, 0},
|
||||
{2, 0, 1, 3},
|
||||
{2, 0, 3, 1},
|
||||
{2, 1, 0, 3},
|
||||
{2, 1, 3, 0},
|
||||
{2, 3, 0, 1},
|
||||
{2, 3, 1, 0},
|
||||
{3, 0, 1, 2},
|
||||
{3, 0, 2, 1},
|
||||
{3, 1, 0, 2},
|
||||
{3, 1, 2, 0},
|
||||
{3, 2, 0, 1},
|
||||
{3, 2, 1, 0}
|
||||
};
|
||||
|
||||
void zr5_hash(const char* input, char* output, uint32_t len)
|
||||
{
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_skein512_context ctx_skein;
|
||||
|
||||
uint32_t hash[5][16];
|
||||
char *ph = (char *)hash;
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512(&ctx_keccak, (const void*) input, len);
|
||||
sph_keccak512_close(&ctx_keccak, (void*) &hash[0][0]);
|
||||
|
||||
unsigned int norder = hash[0][0] % ARRAY_SIZE(permut); /* % 24 */
|
||||
int i;
|
||||
|
||||
for(i=0; i<len; i++) printf("%02x", (unsigned char)input[i]); printf("\n");
|
||||
for(i=0; i<32; i++) printf("%02x", (unsigned char)ph[i]); printf("\n");
|
||||
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
void* phash = (void*) &(hash[i][0]);
|
||||
void* pdest = (void*) &(hash[i+1][0]);
|
||||
|
||||
printf("permut %d\n", permut[norder][i]);
|
||||
switch (permut[norder][i]) {
|
||||
case ZR_BLAKE:
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512(&ctx_blake, (const void*) phash, 64);
|
||||
sph_blake512_close(&ctx_blake, pdest);
|
||||
break;
|
||||
case ZR_GROESTL:
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512(&ctx_groestl, (const void*) phash, 64);
|
||||
sph_groestl512_close(&ctx_groestl, pdest);
|
||||
break;
|
||||
case ZR_JH:
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512(&ctx_jh, (const void*) phash, 64);
|
||||
sph_jh512_close(&ctx_jh, pdest);
|
||||
break;
|
||||
case ZR_SKEIN:
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512(&ctx_skein, (const void*) phash, 64);
|
||||
sph_skein512_close(&ctx_skein, pdest);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
memcpy(output, &hash[4], 32);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
#ifndef ZR5_H
|
||||
#define ZR5_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void zr5_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef ZR5_H
|
||||
#define ZR5_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void zr5_hash(const char* input, char* output, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
284
stratum/client.h
284
stratum/client.h
|
@ -1,142 +1,142 @@
|
|||
|
||||
//struct YAAMP_SOURCE
|
||||
//{
|
||||
//public:
|
||||
// int count;
|
||||
// double speed;
|
||||
//
|
||||
// char ip[1024];
|
||||
//};
|
||||
|
||||
struct YAAMP_ALGO
|
||||
{
|
||||
char name[1024];
|
||||
YAAMP_HASH_FUNCTION hash_function;
|
||||
|
||||
double diff_multiplier;
|
||||
double factor;
|
||||
|
||||
double profit;
|
||||
double rent;
|
||||
|
||||
bool overflow;
|
||||
};
|
||||
|
||||
struct YAAMP_CLIENT_ALGO
|
||||
{
|
||||
double factor;
|
||||
YAAMP_ALGO *algo;
|
||||
};
|
||||
|
||||
#define YAAMP_JOB_MAXHISTORY 16
|
||||
|
||||
class YAAMP_CLIENT: public YAAMP_OBJECT
|
||||
{
|
||||
public:
|
||||
YAAMP_SOCKET *sock;
|
||||
// YAAMP_SOURCE *source;
|
||||
|
||||
char notify_id[1024];
|
||||
|
||||
int created;
|
||||
int last_best;
|
||||
|
||||
bool reconnectable;
|
||||
bool reconnecting;
|
||||
|
||||
int userid;
|
||||
int workerid;
|
||||
bool logtraffic;
|
||||
|
||||
int id_int;
|
||||
const char *id_str;
|
||||
|
||||
char version[1024];
|
||||
char username[1024];
|
||||
char password[1024];
|
||||
char worker[1024];
|
||||
|
||||
double difficulty_actual;
|
||||
double difficulty_remote;
|
||||
double difficulty_written;
|
||||
bool difficulty_fixed;
|
||||
|
||||
long long last_submit_time;
|
||||
double shares_per_minute;
|
||||
|
||||
char extranonce1[32];
|
||||
int extranonce2size;
|
||||
|
||||
char extranonce1_default[32];
|
||||
int extranonce2size_default;
|
||||
|
||||
char extranonce1_last[32];
|
||||
int extranonce2size_last;
|
||||
|
||||
char extranonce1_reconnect[32];
|
||||
int extranonce2size_reconnect;
|
||||
|
||||
bool extranonce_subscribe;
|
||||
int submit_bad;
|
||||
|
||||
double speed;
|
||||
int extranonce1_id;
|
||||
|
||||
int jobid_next;
|
||||
int jobid_sent;
|
||||
int jobid_locked;
|
||||
|
||||
YAAMP_CLIENT_ALGO algos_subscribed[YAAMP_MAXALGOS];
|
||||
int job_history[YAAMP_JOB_MAXHISTORY];
|
||||
};
|
||||
|
||||
inline void client_delete(YAAMP_OBJECT *object)
|
||||
{
|
||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)object;
|
||||
socket_close(client->sock);
|
||||
|
||||
delete client;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
YAAMP_CLIENT *client_find_notify_id(const char *notify_id, bool reconnecting);
|
||||
|
||||
void get_next_extraonce1(char *extraonce1);
|
||||
void get_random_key(char *key);
|
||||
|
||||
void client_sort();
|
||||
void client_block_ip(YAAMP_CLIENT *client, const char *reason);
|
||||
|
||||
bool client_reset_multialgo(YAAMP_CLIENT *client, bool first);
|
||||
bool client_initialize_multialgo(YAAMP_CLIENT *client);
|
||||
|
||||
void client_add_job_history(YAAMP_CLIENT *client, int jobid);
|
||||
bool client_find_job_history(YAAMP_CLIENT *client, int jobid, int startat=1);
|
||||
|
||||
bool client_find_my_ip(const char *ip);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int client_send_difficulty(YAAMP_CLIENT *client, double difficulty);
|
||||
double client_normalize_difficulty(double difficulty);
|
||||
|
||||
void client_change_difficulty(YAAMP_CLIENT *client, double difficulty);
|
||||
void client_record_difficulty(YAAMP_CLIENT *client);
|
||||
void client_adjust_difficulty(YAAMP_CLIENT *client);
|
||||
|
||||
void client_initialize_difficulty(YAAMP_CLIENT *client);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int client_call(YAAMP_CLIENT *client, const char *method, const char *format, ...);
|
||||
void client_dump_all();
|
||||
|
||||
int client_send_result(YAAMP_CLIENT *client, const char *format, ...);
|
||||
int client_send_error(YAAMP_CLIENT *client, int error, const char *string);
|
||||
|
||||
bool client_submit(YAAMP_CLIENT *client, json_value *json_params);
|
||||
void *client_thread(void *p);
|
||||
|
||||
//void source_prune();
|
||||
|
||||
|
||||
//struct YAAMP_SOURCE
|
||||
//{
|
||||
//public:
|
||||
// int count;
|
||||
// double speed;
|
||||
//
|
||||
// char ip[1024];
|
||||
//};
|
||||
|
||||
struct YAAMP_ALGO
|
||||
{
|
||||
char name[1024];
|
||||
YAAMP_HASH_FUNCTION hash_function;
|
||||
|
||||
double diff_multiplier;
|
||||
double factor;
|
||||
|
||||
double profit;
|
||||
double rent;
|
||||
|
||||
bool overflow;
|
||||
};
|
||||
|
||||
struct YAAMP_CLIENT_ALGO
|
||||
{
|
||||
double factor;
|
||||
YAAMP_ALGO *algo;
|
||||
};
|
||||
|
||||
#define YAAMP_JOB_MAXHISTORY 16
|
||||
|
||||
class YAAMP_CLIENT: public YAAMP_OBJECT
|
||||
{
|
||||
public:
|
||||
YAAMP_SOCKET *sock;
|
||||
// YAAMP_SOURCE *source;
|
||||
|
||||
char notify_id[1024];
|
||||
|
||||
int created;
|
||||
int last_best;
|
||||
|
||||
bool reconnectable;
|
||||
bool reconnecting;
|
||||
|
||||
int userid;
|
||||
int workerid;
|
||||
bool logtraffic;
|
||||
|
||||
int id_int;
|
||||
const char *id_str;
|
||||
|
||||
char version[1024];
|
||||
char username[1024];
|
||||
char password[1024];
|
||||
char worker[1024];
|
||||
|
||||
double difficulty_actual;
|
||||
double difficulty_remote;
|
||||
double difficulty_written;
|
||||
bool difficulty_fixed;
|
||||
|
||||
long long last_submit_time;
|
||||
double shares_per_minute;
|
||||
|
||||
char extranonce1[32];
|
||||
int extranonce2size;
|
||||
|
||||
char extranonce1_default[32];
|
||||
int extranonce2size_default;
|
||||
|
||||
char extranonce1_last[32];
|
||||
int extranonce2size_last;
|
||||
|
||||
char extranonce1_reconnect[32];
|
||||
int extranonce2size_reconnect;
|
||||
|
||||
bool extranonce_subscribe;
|
||||
int submit_bad;
|
||||
|
||||
double speed;
|
||||
int extranonce1_id;
|
||||
|
||||
int jobid_next;
|
||||
int jobid_sent;
|
||||
int jobid_locked;
|
||||
|
||||
YAAMP_CLIENT_ALGO algos_subscribed[YAAMP_MAXALGOS];
|
||||
int job_history[YAAMP_JOB_MAXHISTORY];
|
||||
};
|
||||
|
||||
inline void client_delete(YAAMP_OBJECT *object)
|
||||
{
|
||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)object;
|
||||
socket_close(client->sock);
|
||||
|
||||
delete client;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
YAAMP_CLIENT *client_find_notify_id(const char *notify_id, bool reconnecting);
|
||||
|
||||
void get_next_extraonce1(char *extraonce1);
|
||||
void get_random_key(char *key);
|
||||
|
||||
void client_sort();
|
||||
void client_block_ip(YAAMP_CLIENT *client, const char *reason);
|
||||
|
||||
bool client_reset_multialgo(YAAMP_CLIENT *client, bool first);
|
||||
bool client_initialize_multialgo(YAAMP_CLIENT *client);
|
||||
|
||||
void client_add_job_history(YAAMP_CLIENT *client, int jobid);
|
||||
bool client_find_job_history(YAAMP_CLIENT *client, int jobid, int startat=1);
|
||||
|
||||
bool client_find_my_ip(const char *ip);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int client_send_difficulty(YAAMP_CLIENT *client, double difficulty);
|
||||
double client_normalize_difficulty(double difficulty);
|
||||
|
||||
void client_change_difficulty(YAAMP_CLIENT *client, double difficulty);
|
||||
void client_record_difficulty(YAAMP_CLIENT *client);
|
||||
void client_adjust_difficulty(YAAMP_CLIENT *client);
|
||||
|
||||
void client_initialize_difficulty(YAAMP_CLIENT *client);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int client_call(YAAMP_CLIENT *client, const char *method, const char *format, ...);
|
||||
void client_dump_all();
|
||||
|
||||
int client_send_result(YAAMP_CLIENT *client, const char *format, ...);
|
||||
int client_send_error(YAAMP_CLIENT *client, int error, const char *string);
|
||||
|
||||
bool client_submit(YAAMP_CLIENT *client, json_value *json_params);
|
||||
void *client_thread(void *p);
|
||||
|
||||
//void source_prune();
|
||||
|
||||
|
|
|
@ -1,312 +1,312 @@
|
|||
|
||||
#include "stratum.h"
|
||||
|
||||
static int g_extraonce1_counter = 0;
|
||||
|
||||
void get_next_extraonce1(char *extraonce1)
|
||||
{
|
||||
CommonLock(&g_nonce1_mutex);
|
||||
|
||||
g_extraonce1_counter++;
|
||||
sprintf(extraonce1, "%08x", g_extraonce1_counter|0x81000000);
|
||||
|
||||
CommonUnlock(&g_nonce1_mutex);
|
||||
}
|
||||
|
||||
void get_random_key(char *key)
|
||||
{
|
||||
int i1 = rand();
|
||||
int i2 = rand();
|
||||
int i3 = rand();
|
||||
int i4 = rand();
|
||||
sprintf(key, "%08x%08x%08x%08x", i1, i2, i3, i4);
|
||||
}
|
||||
|
||||
YAAMP_CLIENT *client_find_notify_id(const char *notify_id, bool reconnecting)
|
||||
{
|
||||
g_list_client.Enter();
|
||||
for(CLI li = g_list_client.first; li; li = li->next)
|
||||
{
|
||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
||||
if(client->reconnecting == reconnecting && !strcmp(client->notify_id, notify_id))
|
||||
{
|
||||
g_list_client.Leave();
|
||||
return client;
|
||||
}
|
||||
}
|
||||
|
||||
g_list_client.Leave();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void client_sort()
|
||||
{
|
||||
for(CLI li = g_list_client.first; li && li->next; li = li->next)
|
||||
{
|
||||
YAAMP_CLIENT *client1 = (YAAMP_CLIENT *)li->data;
|
||||
YAAMP_CLIENT *client2 = (YAAMP_CLIENT *)li->next->data;
|
||||
|
||||
// if(client2->difficulty_actual > client1->difficulty_actual)
|
||||
if(client2->speed > client1->speed*1.5)
|
||||
{
|
||||
g_list_client.Swap(li, li->next);
|
||||
client_sort();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int client_send_error(YAAMP_CLIENT *client, int error, const char *string)
|
||||
{
|
||||
char buffer3[1024];
|
||||
|
||||
if(client->id_str)
|
||||
sprintf(buffer3, "\"%s\"", client->id_str);
|
||||
else
|
||||
sprintf(buffer3, "%d", client->id_int);
|
||||
|
||||
return socket_send(client->sock, "{\"id\":%s,\"result\":false,\"error\":[%d,\"%s\",null]}\n", buffer3, error, string);
|
||||
}
|
||||
|
||||
int client_send_result(YAAMP_CLIENT *client, const char *format, ...)
|
||||
{
|
||||
char buffer[YAAMP_SMALLBUFSIZE];
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
vsprintf(buffer, format, args);
|
||||
va_end(args);
|
||||
|
||||
char buffer3[1024];
|
||||
|
||||
if(client->id_str)
|
||||
sprintf(buffer3, "\"%s\"", client->id_str);
|
||||
else
|
||||
sprintf(buffer3, "%d", client->id_int);
|
||||
|
||||
return socket_send(client->sock, "{\"id\":%s,\"result\":%s,\"error\":null}\n", buffer3, buffer);
|
||||
}
|
||||
|
||||
int client_call(YAAMP_CLIENT *client, const char *method, const char *format, ...)
|
||||
{
|
||||
char buffer[YAAMP_SMALLBUFSIZE];
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
vsprintf(buffer, format, args);
|
||||
va_end(args);
|
||||
|
||||
return socket_send(client->sock, "{\"id\":null,\"method\":\"%s\",\"params\":%s}\n", method, buffer);
|
||||
}
|
||||
|
||||
void client_block_ip(YAAMP_CLIENT *client, const char *reason)
|
||||
{
|
||||
char buffer[1024];
|
||||
|
||||
sprintf(buffer, "iptables -A INPUT -s %s -j DROP", client->sock->ip);
|
||||
int s = system(buffer);
|
||||
|
||||
stratumlog("%s %s blocked (%s)\n", client->sock->ip, client->username, reason);
|
||||
}
|
||||
|
||||
bool client_reset_multialgo(YAAMP_CLIENT *client, bool first)
|
||||
{
|
||||
// return false;
|
||||
if(!client->algos_subscribed[0].algo) return false;
|
||||
// debuglog("client_reset_multialgo\n");
|
||||
|
||||
YAAMP_CLIENT_ALGO *best = NULL;
|
||||
YAAMP_CLIENT_ALGO *current = NULL;
|
||||
|
||||
for(int i=0; g_algos[i].name[0]; i++)
|
||||
{
|
||||
YAAMP_ALGO *algo = &g_algos[i];
|
||||
for(int j=0; client->algos_subscribed[j].algo; j++)
|
||||
{
|
||||
YAAMP_CLIENT_ALGO *candidate = &client->algos_subscribed[j];
|
||||
if(candidate->algo == algo)
|
||||
{
|
||||
if(!best || algo->profit*candidate->factor > best->algo->profit*best->factor)
|
||||
best = candidate;
|
||||
}
|
||||
|
||||
if(!current && candidate->algo == g_current_algo)
|
||||
current = candidate;
|
||||
}
|
||||
}
|
||||
|
||||
if(!best || !current || best == current)
|
||||
{
|
||||
client->last_best = time(NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!first)
|
||||
{
|
||||
int e = time(NULL) - client->last_best;
|
||||
double d = best->algo->profit*best->factor - current->algo->profit*current->factor;
|
||||
double p = d/best->algo->profit/best->factor;
|
||||
|
||||
// debuglog("current %s %f\n", current->algo->name, current->algo->profit*current->factor);
|
||||
// debuglog("best %s %f\n", best->algo->name, best->algo->profit*best->factor);
|
||||
// debuglog(" %d * %f = %f --- percent %f %f\n", e, d, e*d, p, e*p);
|
||||
|
||||
if(p < 0.02) return false;
|
||||
if(e*p < 100) return false;
|
||||
}
|
||||
|
||||
shutdown(client->sock->sock, SHUT_RDWR);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool client_initialize_multialgo(YAAMP_CLIENT *client)
|
||||
{
|
||||
char *p = strstr(client->password, "p=");
|
||||
if(p)
|
||||
{
|
||||
double profit = atof(p+2);
|
||||
if(profit > g_current_algo->profit)
|
||||
return true;
|
||||
}
|
||||
|
||||
char tmp[1024];
|
||||
memset(tmp, 0, 1024);
|
||||
strncpy(tmp, client->password, 1023);
|
||||
|
||||
p = tmp;
|
||||
while(p)
|
||||
{
|
||||
double value = 0;
|
||||
|
||||
char *p1 = strchr(p, ',');
|
||||
if(p1) *p1 = 0;
|
||||
|
||||
char *p2 = strchr(p, '=');
|
||||
if(p2)
|
||||
{
|
||||
*p2 = 0;
|
||||
value = atof(p2+1);
|
||||
}
|
||||
|
||||
for(int i=0; g_algos[i].name[0]; i++)
|
||||
{
|
||||
YAAMP_ALGO *algo = &g_algos[i];
|
||||
if(!strcmp(algo->name, p))
|
||||
{
|
||||
int i=0;
|
||||
for(; i<YAAMP_MAXALGOS-1 && client->algos_subscribed[i].algo; i++);
|
||||
|
||||
client->algos_subscribed[i].algo = algo;
|
||||
client->algos_subscribed[i].factor = value? value: algo->factor;
|
||||
}
|
||||
}
|
||||
|
||||
p = p1? p1+1: p1;
|
||||
}
|
||||
|
||||
bool reset = client_reset_multialgo(client, true);
|
||||
return reset;
|
||||
}
|
||||
|
||||
void client_add_job_history(YAAMP_CLIENT *client, int jobid)
|
||||
{
|
||||
if(!jobid)
|
||||
{
|
||||
debuglog("trying to add jobid 0\n");
|
||||
return;
|
||||
}
|
||||
|
||||
bool b = client_find_job_history(client, jobid, 0);
|
||||
if(b)
|
||||
{
|
||||
// debuglog("ERROR history already added job %x\n", jobid);
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i=YAAMP_JOB_MAXHISTORY-1; i>0; i--)
|
||||
client->job_history[i] = client->job_history[i-1];
|
||||
|
||||
client->job_history[0] = jobid;
|
||||
}
|
||||
|
||||
bool client_find_job_history(YAAMP_CLIENT *client, int jobid, int startat)
|
||||
{
|
||||
for(int i=startat; i<YAAMP_JOB_MAXHISTORY; i++)
|
||||
{
|
||||
if(client->job_history[i] == jobid)
|
||||
{
|
||||
// if(!startat)
|
||||
// debuglog("job %x already sent, index %d\n", jobid, i);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int hostname_to_ip(const char *hostname , char* ip)
|
||||
{
|
||||
struct hostent *he;
|
||||
struct in_addr **addr_list;
|
||||
int i;
|
||||
|
||||
if(hostname[0]>='0' && hostname[0]<='9')
|
||||
{
|
||||
strcpy(ip, hostname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( (he = gethostbyname( hostname ) ) == NULL)
|
||||
{
|
||||
// get the host info
|
||||
herror("gethostbyname");
|
||||
return 1;
|
||||
}
|
||||
|
||||
addr_list = (struct in_addr **) he->h_addr_list;
|
||||
|
||||
for(i = 0; addr_list[i] != NULL; i++)
|
||||
{
|
||||
//Return the first one;
|
||||
strcpy(ip, inet_ntoa(*addr_list[i]));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool client_find_my_ip(const char *name)
|
||||
{
|
||||
// return false;
|
||||
char ip[1024] = "";
|
||||
|
||||
hostname_to_ip(name, ip);
|
||||
if(!ip[0]) return false;
|
||||
|
||||
char host[NI_MAXHOST];
|
||||
for(struct ifaddrs *ifa = g_ifaddr; ifa != NULL; ifa = ifa->ifa_next)
|
||||
{
|
||||
if(ifa->ifa_addr == NULL) continue;
|
||||
host[0] = 0;
|
||||
|
||||
getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
||||
if(!host[0]) continue;
|
||||
|
||||
if(!strcmp(host, ip))
|
||||
{
|
||||
debuglog("found my ip %s\n", ip);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "stratum.h"
|
||||
|
||||
static int g_extraonce1_counter = 0;
|
||||
|
||||
void get_next_extraonce1(char *extraonce1)
|
||||
{
|
||||
CommonLock(&g_nonce1_mutex);
|
||||
|
||||
g_extraonce1_counter++;
|
||||
sprintf(extraonce1, "%08x", g_extraonce1_counter|0x81000000);
|
||||
|
||||
CommonUnlock(&g_nonce1_mutex);
|
||||
}
|
||||
|
||||
void get_random_key(char *key)
|
||||
{
|
||||
int i1 = rand();
|
||||
int i2 = rand();
|
||||
int i3 = rand();
|
||||
int i4 = rand();
|
||||
sprintf(key, "%08x%08x%08x%08x", i1, i2, i3, i4);
|
||||
}
|
||||
|
||||
YAAMP_CLIENT *client_find_notify_id(const char *notify_id, bool reconnecting)
|
||||
{
|
||||
g_list_client.Enter();
|
||||
for(CLI li = g_list_client.first; li; li = li->next)
|
||||
{
|
||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
||||
if(client->reconnecting == reconnecting && !strcmp(client->notify_id, notify_id))
|
||||
{
|
||||
g_list_client.Leave();
|
||||
return client;
|
||||
}
|
||||
}
|
||||
|
||||
g_list_client.Leave();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void client_sort()
|
||||
{
|
||||
for(CLI li = g_list_client.first; li && li->next; li = li->next)
|
||||
{
|
||||
YAAMP_CLIENT *client1 = (YAAMP_CLIENT *)li->data;
|
||||
YAAMP_CLIENT *client2 = (YAAMP_CLIENT *)li->next->data;
|
||||
|
||||
// if(client2->difficulty_actual > client1->difficulty_actual)
|
||||
if(client2->speed > client1->speed*1.5)
|
||||
{
|
||||
g_list_client.Swap(li, li->next);
|
||||
client_sort();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int client_send_error(YAAMP_CLIENT *client, int error, const char *string)
|
||||
{
|
||||
char buffer3[1024];
|
||||
|
||||
if(client->id_str)
|
||||
sprintf(buffer3, "\"%s\"", client->id_str);
|
||||
else
|
||||
sprintf(buffer3, "%d", client->id_int);
|
||||
|
||||
return socket_send(client->sock, "{\"id\":%s,\"result\":false,\"error\":[%d,\"%s\",null]}\n", buffer3, error, string);
|
||||
}
|
||||
|
||||
int client_send_result(YAAMP_CLIENT *client, const char *format, ...)
|
||||
{
|
||||
char buffer[YAAMP_SMALLBUFSIZE];
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
vsprintf(buffer, format, args);
|
||||
va_end(args);
|
||||
|
||||
char buffer3[1024];
|
||||
|
||||
if(client->id_str)
|
||||
sprintf(buffer3, "\"%s\"", client->id_str);
|
||||
else
|
||||
sprintf(buffer3, "%d", client->id_int);
|
||||
|
||||
return socket_send(client->sock, "{\"id\":%s,\"result\":%s,\"error\":null}\n", buffer3, buffer);
|
||||
}
|
||||
|
||||
int client_call(YAAMP_CLIENT *client, const char *method, const char *format, ...)
|
||||
{
|
||||
char buffer[YAAMP_SMALLBUFSIZE];
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
vsprintf(buffer, format, args);
|
||||
va_end(args);
|
||||
|
||||
return socket_send(client->sock, "{\"id\":null,\"method\":\"%s\",\"params\":%s}\n", method, buffer);
|
||||
}
|
||||
|
||||
void client_block_ip(YAAMP_CLIENT *client, const char *reason)
|
||||
{
|
||||
char buffer[1024];
|
||||
|
||||
sprintf(buffer, "iptables -A INPUT -s %s -j DROP", client->sock->ip);
|
||||
int s = system(buffer);
|
||||
|
||||
stratumlog("%s %s blocked (%s)\n", client->sock->ip, client->username, reason);
|
||||
}
|
||||
|
||||
bool client_reset_multialgo(YAAMP_CLIENT *client, bool first)
|
||||
{
|
||||
// return false;
|
||||
if(!client->algos_subscribed[0].algo) return false;
|
||||
// debuglog("client_reset_multialgo\n");
|
||||
|
||||
YAAMP_CLIENT_ALGO *best = NULL;
|
||||
YAAMP_CLIENT_ALGO *current = NULL;
|
||||
|
||||
for(int i=0; g_algos[i].name[0]; i++)
|
||||
{
|
||||
YAAMP_ALGO *algo = &g_algos[i];
|
||||
for(int j=0; client->algos_subscribed[j].algo; j++)
|
||||
{
|
||||
YAAMP_CLIENT_ALGO *candidate = &client->algos_subscribed[j];
|
||||
if(candidate->algo == algo)
|
||||
{
|
||||
if(!best || algo->profit*candidate->factor > best->algo->profit*best->factor)
|
||||
best = candidate;
|
||||
}
|
||||
|
||||
if(!current && candidate->algo == g_current_algo)
|
||||
current = candidate;
|
||||
}
|
||||
}
|
||||
|
||||
if(!best || !current || best == current)
|
||||
{
|
||||
client->last_best = time(NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!first)
|
||||
{
|
||||
int e = time(NULL) - client->last_best;
|
||||
double d = best->algo->profit*best->factor - current->algo->profit*current->factor;
|
||||
double p = d/best->algo->profit/best->factor;
|
||||
|
||||
// debuglog("current %s %f\n", current->algo->name, current->algo->profit*current->factor);
|
||||
// debuglog("best %s %f\n", best->algo->name, best->algo->profit*best->factor);
|
||||
// debuglog(" %d * %f = %f --- percent %f %f\n", e, d, e*d, p, e*p);
|
||||
|
||||
if(p < 0.02) return false;
|
||||
if(e*p < 100) return false;
|
||||
}
|
||||
|
||||
shutdown(client->sock->sock, SHUT_RDWR);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool client_initialize_multialgo(YAAMP_CLIENT *client)
|
||||
{
|
||||
char *p = strstr(client->password, "p=");
|
||||
if(p)
|
||||
{
|
||||
double profit = atof(p+2);
|
||||
if(profit > g_current_algo->profit)
|
||||
return true;
|
||||
}
|
||||
|
||||
char tmp[1024];
|
||||
memset(tmp, 0, 1024);
|
||||
strncpy(tmp, client->password, 1023);
|
||||
|
||||
p = tmp;
|
||||
while(p)
|
||||
{
|
||||
double value = 0;
|
||||
|
||||
char *p1 = strchr(p, ',');
|
||||
if(p1) *p1 = 0;
|
||||
|
||||
char *p2 = strchr(p, '=');
|
||||
if(p2)
|
||||
{
|
||||
*p2 = 0;
|
||||
value = atof(p2+1);
|
||||
}
|
||||
|
||||
for(int i=0; g_algos[i].name[0]; i++)
|
||||
{
|
||||
YAAMP_ALGO *algo = &g_algos[i];
|
||||
if(!strcmp(algo->name, p))
|
||||
{
|
||||
int i=0;
|
||||
for(; i<YAAMP_MAXALGOS-1 && client->algos_subscribed[i].algo; i++);
|
||||
|
||||
client->algos_subscribed[i].algo = algo;
|
||||
client->algos_subscribed[i].factor = value? value: algo->factor;
|
||||
}
|
||||
}
|
||||
|
||||
p = p1? p1+1: p1;
|
||||
}
|
||||
|
||||
bool reset = client_reset_multialgo(client, true);
|
||||
return reset;
|
||||
}
|
||||
|
||||
void client_add_job_history(YAAMP_CLIENT *client, int jobid)
|
||||
{
|
||||
if(!jobid)
|
||||
{
|
||||
debuglog("trying to add jobid 0\n");
|
||||
return;
|
||||
}
|
||||
|
||||
bool b = client_find_job_history(client, jobid, 0);
|
||||
if(b)
|
||||
{
|
||||
// debuglog("ERROR history already added job %x\n", jobid);
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i=YAAMP_JOB_MAXHISTORY-1; i>0; i--)
|
||||
client->job_history[i] = client->job_history[i-1];
|
||||
|
||||
client->job_history[0] = jobid;
|
||||
}
|
||||
|
||||
bool client_find_job_history(YAAMP_CLIENT *client, int jobid, int startat)
|
||||
{
|
||||
for(int i=startat; i<YAAMP_JOB_MAXHISTORY; i++)
|
||||
{
|
||||
if(client->job_history[i] == jobid)
|
||||
{
|
||||
// if(!startat)
|
||||
// debuglog("job %x already sent, index %d\n", jobid, i);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int hostname_to_ip(const char *hostname , char* ip)
|
||||
{
|
||||
struct hostent *he;
|
||||
struct in_addr **addr_list;
|
||||
int i;
|
||||
|
||||
if(hostname[0]>='0' && hostname[0]<='9')
|
||||
{
|
||||
strcpy(ip, hostname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( (he = gethostbyname( hostname ) ) == NULL)
|
||||
{
|
||||
// get the host info
|
||||
herror("gethostbyname");
|
||||
return 1;
|
||||
}
|
||||
|
||||
addr_list = (struct in_addr **) he->h_addr_list;
|
||||
|
||||
for(i = 0; addr_list[i] != NULL; i++)
|
||||
{
|
||||
//Return the first one;
|
||||
strcpy(ip, inet_ntoa(*addr_list[i]));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool client_find_my_ip(const char *name)
|
||||
{
|
||||
// return false;
|
||||
char ip[1024] = "";
|
||||
|
||||
hostname_to_ip(name, ip);
|
||||
if(!ip[0]) return false;
|
||||
|
||||
char host[NI_MAXHOST];
|
||||
for(struct ifaddrs *ifa = g_ifaddr; ifa != NULL; ifa = ifa->ifa_next)
|
||||
{
|
||||
if(ifa->ifa_addr == NULL) continue;
|
||||
host[0] = 0;
|
||||
|
||||
getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
||||
if(!host[0]) continue;
|
||||
|
||||
if(!strcmp(host, ip))
|
||||
{
|
||||
debuglog("found my ip %s\n", ip);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,105 +1,105 @@
|
|||
|
||||
#include "stratum.h"
|
||||
|
||||
double client_normalize_difficulty(double difficulty)
|
||||
{
|
||||
if(difficulty <= 0.001) difficulty = 0.001;
|
||||
else if(difficulty < 1) difficulty = floor(difficulty*1000/2)/1000*2;
|
||||
else if(difficulty > 1) difficulty = floor(difficulty/2)*2;
|
||||
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
void client_record_difficulty(YAAMP_CLIENT *client)
|
||||
{
|
||||
if(client->difficulty_remote)
|
||||
{
|
||||
client->last_submit_time = current_timestamp();
|
||||
return;
|
||||
}
|
||||
|
||||
int e = current_timestamp() - client->last_submit_time;
|
||||
if(e < 500) e = 500;
|
||||
int p = 5;
|
||||
|
||||
client->shares_per_minute = (client->shares_per_minute * (100 - p) + 60*1000*p/e) / 100;
|
||||
client->last_submit_time = current_timestamp();
|
||||
|
||||
// debuglog("client->shares_per_minute %f\n", client->shares_per_minute);
|
||||
}
|
||||
|
||||
void client_change_difficulty(YAAMP_CLIENT *client, double difficulty)
|
||||
{
|
||||
if(difficulty <= 0) return;
|
||||
|
||||
difficulty = client_normalize_difficulty(difficulty);
|
||||
if(difficulty <= 0) return;
|
||||
|
||||
// debuglog("change diff to %f %f\n", difficulty, client->difficulty_actual);
|
||||
if(difficulty == client->difficulty_actual) return;
|
||||
|
||||
uint64_t user_target = diff_to_target(difficulty);
|
||||
if(user_target >= YAAMP_MINDIFF && user_target <= YAAMP_MAXDIFF)
|
||||
{
|
||||
client->difficulty_actual = difficulty;
|
||||
client_send_difficulty(client, difficulty);
|
||||
}
|
||||
}
|
||||
|
||||
void client_adjust_difficulty(YAAMP_CLIENT *client)
|
||||
{
|
||||
if(client->difficulty_remote)
|
||||
{
|
||||
client_change_difficulty(client, client->difficulty_remote);
|
||||
return;
|
||||
}
|
||||
|
||||
if(client->shares_per_minute > 600)
|
||||
client_change_difficulty(client, client->difficulty_actual*4);
|
||||
|
||||
else if(client->difficulty_fixed)
|
||||
return;
|
||||
|
||||
else if(client->shares_per_minute > 25)
|
||||
client_change_difficulty(client, client->difficulty_actual*2);
|
||||
|
||||
else if(client->shares_per_minute > 20)
|
||||
client_change_difficulty(client, client->difficulty_actual*1.5);
|
||||
|
||||
else if(client->shares_per_minute < 5)
|
||||
client_change_difficulty(client, client->difficulty_actual/2);
|
||||
}
|
||||
|
||||
int client_send_difficulty(YAAMP_CLIENT *client, double difficulty)
|
||||
{
|
||||
// debuglog("%s diff %f\n", client->sock->ip, difficulty);
|
||||
client->shares_per_minute = YAAMP_SHAREPERSEC;
|
||||
|
||||
if(difficulty >= 1)
|
||||
client_call(client, "mining.set_difficulty", "[%.0f]", difficulty);
|
||||
else
|
||||
client_call(client, "mining.set_difficulty", "[%.3f]", difficulty);
|
||||
}
|
||||
|
||||
void client_initialize_difficulty(YAAMP_CLIENT *client)
|
||||
{
|
||||
char *p = strstr(client->password, "d=");
|
||||
if(!p) return;
|
||||
|
||||
double diff = client_normalize_difficulty(atof(p+2));
|
||||
uint64_t user_target = diff_to_target(diff);
|
||||
|
||||
// debuglog("%016llx target\n", user_target);
|
||||
if(user_target >= YAAMP_MINDIFF && user_target <= YAAMP_MAXDIFF)
|
||||
{
|
||||
client->difficulty_actual = diff;
|
||||
client->difficulty_fixed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "stratum.h"
|
||||
|
||||
double client_normalize_difficulty(double difficulty)
|
||||
{
|
||||
if(difficulty <= 0.001) difficulty = 0.001;
|
||||
else if(difficulty < 1) difficulty = floor(difficulty*1000/2)/1000*2;
|
||||
else if(difficulty > 1) difficulty = floor(difficulty/2)*2;
|
||||
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
void client_record_difficulty(YAAMP_CLIENT *client)
|
||||
{
|
||||
if(client->difficulty_remote)
|
||||
{
|
||||
client->last_submit_time = current_timestamp();
|
||||
return;
|
||||
}
|
||||
|
||||
int e = current_timestamp() - client->last_submit_time;
|
||||
if(e < 500) e = 500;
|
||||
int p = 5;
|
||||
|
||||
client->shares_per_minute = (client->shares_per_minute * (100 - p) + 60*1000*p/e) / 100;
|
||||
client->last_submit_time = current_timestamp();
|
||||
|
||||
// debuglog("client->shares_per_minute %f\n", client->shares_per_minute);
|
||||
}
|
||||
|
||||
void client_change_difficulty(YAAMP_CLIENT *client, double difficulty)
|
||||
{
|
||||
if(difficulty <= 0) return;
|
||||
|
||||
difficulty = client_normalize_difficulty(difficulty);
|
||||
if(difficulty <= 0) return;
|
||||
|
||||
// debuglog("change diff to %f %f\n", difficulty, client->difficulty_actual);
|
||||
if(difficulty == client->difficulty_actual) return;
|
||||
|
||||
uint64_t user_target = diff_to_target(difficulty);
|
||||
if(user_target >= YAAMP_MINDIFF && user_target <= YAAMP_MAXDIFF)
|
||||
{
|
||||
client->difficulty_actual = difficulty;
|
||||
client_send_difficulty(client, difficulty);
|
||||
}
|
||||
}
|
||||
|
||||
void client_adjust_difficulty(YAAMP_CLIENT *client)
|
||||
{
|
||||
if(client->difficulty_remote)
|
||||
{
|
||||
client_change_difficulty(client, client->difficulty_remote);
|
||||
return;
|
||||
}
|
||||
|
||||
if(client->shares_per_minute > 600)
|
||||
client_change_difficulty(client, client->difficulty_actual*4);
|
||||
|
||||
else if(client->difficulty_fixed)
|
||||
return;
|
||||
|
||||
else if(client->shares_per_minute > 25)
|
||||
client_change_difficulty(client, client->difficulty_actual*2);
|
||||
|
||||
else if(client->shares_per_minute > 20)
|
||||
client_change_difficulty(client, client->difficulty_actual*1.5);
|
||||
|
||||
else if(client->shares_per_minute < 5)
|
||||
client_change_difficulty(client, client->difficulty_actual/2);
|
||||
}
|
||||
|
||||
int client_send_difficulty(YAAMP_CLIENT *client, double difficulty)
|
||||
{
|
||||
// debuglog("%s diff %f\n", client->sock->ip, difficulty);
|
||||
client->shares_per_minute = YAAMP_SHAREPERSEC;
|
||||
|
||||
if(difficulty >= 1)
|
||||
client_call(client, "mining.set_difficulty", "[%.0f]", difficulty);
|
||||
else
|
||||
client_call(client, "mining.set_difficulty", "[%.3f]", difficulty);
|
||||
}
|
||||
|
||||
void client_initialize_difficulty(YAAMP_CLIENT *client)
|
||||
{
|
||||
char *p = strstr(client->password, "d=");
|
||||
if(!p) return;
|
||||
|
||||
double diff = client_normalize_difficulty(atof(p+2));
|
||||
uint64_t user_target = diff_to_target(diff);
|
||||
|
||||
// debuglog("%016llx target\n", user_target);
|
||||
if(user_target >= YAAMP_MINDIFF && user_target <= YAAMP_MAXDIFF)
|
||||
{
|
||||
client->difficulty_actual = diff;
|
||||
client->difficulty_fixed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,139 +1,139 @@
|
|||
|
||||
// http://www.righto.com/2014/02/bitcoin-mining-hard-way-algorithms.html
|
||||
|
||||
// https://en.bitcoin.it/wiki/Merged_mining_specification#Merged_mining_coinbase
|
||||
|
||||
#include "stratum.h"
|
||||
|
||||
#define TX_VALUE(v, s) ((unsigned int)(v>>s)&0xff)
|
||||
|
||||
static void encode_tx_value(char *encoded, json_int_t value)
|
||||
{
|
||||
sprintf(encoded, "%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||
TX_VALUE(value, 0), TX_VALUE(value, 8), TX_VALUE(value, 16), TX_VALUE(value, 24),
|
||||
TX_VALUE(value, 32), TX_VALUE(value, 40), TX_VALUE(value, 48), TX_VALUE(value, 56));
|
||||
}
|
||||
|
||||
static void job_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, char *key)
|
||||
{
|
||||
int ol = strlen(data);
|
||||
char evalue[64];
|
||||
encode_tx_value(evalue, amount);
|
||||
|
||||
sprintf(data+strlen(data), "%s", evalue);
|
||||
|
||||
if(coind->pos && !key)
|
||||
sprintf(data+strlen(data), "2321%sac", coind->pubkey);
|
||||
|
||||
else
|
||||
sprintf(data+strlen(data), "1976a914%s88ac", key? key: coind->script_pubkey);
|
||||
|
||||
// debuglog("pack tx %s\n", data+ol);
|
||||
// debuglog("pack tx %lld\n", amount);
|
||||
}
|
||||
|
||||
void coinbase_aux(YAAMP_JOB_TEMPLATE *templ, char *aux_script)
|
||||
{
|
||||
vector<string> hashlist = coind_aux_hashlist(templ->auxs, templ->auxs_size);
|
||||
while(hashlist.size() > 1)
|
||||
{
|
||||
vector<string> l;
|
||||
for(int i = 0; i < hashlist.size()/2; i++)
|
||||
{
|
||||
string s = hashlist[i*2] + hashlist[i*2+1];
|
||||
|
||||
char bin[YAAMP_HASHLEN_BIN*2];
|
||||
char out[YAAMP_HASHLEN_STR];
|
||||
|
||||
binlify((unsigned char *)bin, s.c_str());
|
||||
sha256_double_hash_hex(bin, out, YAAMP_HASHLEN_BIN*2);
|
||||
|
||||
l.push_back(out);
|
||||
}
|
||||
|
||||
hashlist = l;
|
||||
}
|
||||
|
||||
char merkle_hash[4*1024];
|
||||
memset(merkle_hash, 0, 4*1024);
|
||||
string_be(hashlist[0].c_str(), merkle_hash);
|
||||
|
||||
sprintf(aux_script+strlen(aux_script), "fabe6d6d%s%02x00000000000000", merkle_hash, templ->auxs_size);
|
||||
// debuglog("aux_script is %s\n", aux_script);
|
||||
}
|
||||
|
||||
void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value *json_result)
|
||||
{
|
||||
char eheight[64];
|
||||
ser_number(templ->height, eheight);
|
||||
|
||||
char etime[64];
|
||||
ser_number(time(NULL), etime);
|
||||
|
||||
char entime[64];
|
||||
memset(entime, 0, 64);
|
||||
|
||||
if(coind->pos)
|
||||
ser_string_be(templ->ntime, entime, 1);
|
||||
|
||||
char eversion1[64] = "01000000";
|
||||
|
||||
if(coind->txmessage)
|
||||
strcpy(eversion1, "02000000");
|
||||
|
||||
char script1[4*1024];
|
||||
sprintf(script1, "%s%s%s08", eheight, templ->flags, etime);
|
||||
|
||||
char script2[4*1024] = "7961616d702e636f6d00"; // yaamp.com
|
||||
if(!coind->pos && !coind->isaux && templ->auxs_size)
|
||||
coinbase_aux(templ, script2);
|
||||
|
||||
int script_len = strlen(script1)/2 + strlen(script2)/2 + 8;
|
||||
|
||||
sprintf(templ->coinb1,
|
||||
"%s%s010000000000000000000000000000000000000000000000000000000000000000ffffffff%02x%s", // 8+8+74+2 -> height
|
||||
eversion1, entime, script_len, script1);
|
||||
|
||||
sprintf(templ->coinb2, "%s00000000", script2);
|
||||
json_int_t available = templ->value;
|
||||
|
||||
if(strcmp(coind->symbol, "DRK") == 0 || strcmp(coind->symbol, "DASH") == 0)
|
||||
// if(strcmp(coind->symbol, "DRK") == 0)
|
||||
{
|
||||
char charity_payee[1024] = "";
|
||||
strcpy(charity_payee, json_get_string(json_result, "payee"));
|
||||
|
||||
json_int_t charity_amount = json_get_int(json_result, "payee_amount");
|
||||
bool charity_payments = json_get_bool(json_result, "masternode_payments");
|
||||
bool charity_enforce = json_get_bool(json_result, "enforce_masternode_payments");
|
||||
|
||||
if(charity_payments && charity_enforce)
|
||||
{
|
||||
strcat(templ->coinb2, "02");
|
||||
available -= charity_amount;
|
||||
|
||||
char script_payee[1024];
|
||||
base58_decode(charity_payee, script_payee);
|
||||
|
||||
job_pack_tx(coind, templ->coinb2, charity_amount, script_payee);
|
||||
}
|
||||
else
|
||||
strcat(templ->coinb2, "01");
|
||||
}
|
||||
|
||||
else
|
||||
strcat(templ->coinb2, "01");
|
||||
|
||||
job_pack_tx(coind, templ->coinb2, available, NULL);
|
||||
strcat(templ->coinb2, "00000000"); // locktime
|
||||
|
||||
coind->reward = (double)available/100000000*coind->reward_mul;
|
||||
// debuglog("coinbase %f\n", coind->reward);
|
||||
|
||||
// debuglog("new job: %x, %s, %s, %s\n", coind->templ->id, coind->templ->version, coind->templ->nbits, coind->templ->ntime);
|
||||
// debuglog("coinb1 %s\n", templ->coinb1);
|
||||
// debuglog("coinb2 %s\n", templ->coinb2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// http://www.righto.com/2014/02/bitcoin-mining-hard-way-algorithms.html
|
||||
|
||||
// https://en.bitcoin.it/wiki/Merged_mining_specification#Merged_mining_coinbase
|
||||
|
||||
#include "stratum.h"
|
||||
|
||||
#define TX_VALUE(v, s) ((unsigned int)(v>>s)&0xff)
|
||||
|
||||
static void encode_tx_value(char *encoded, json_int_t value)
|
||||
{
|
||||
sprintf(encoded, "%02x%02x%02x%02x%02x%02x%02x%02x",
|
||||
TX_VALUE(value, 0), TX_VALUE(value, 8), TX_VALUE(value, 16), TX_VALUE(value, 24),
|
||||
TX_VALUE(value, 32), TX_VALUE(value, 40), TX_VALUE(value, 48), TX_VALUE(value, 56));
|
||||
}
|
||||
|
||||
static void job_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, char *key)
|
||||
{
|
||||
int ol = strlen(data);
|
||||
char evalue[64];
|
||||
encode_tx_value(evalue, amount);
|
||||
|
||||
sprintf(data+strlen(data), "%s", evalue);
|
||||
|
||||
if(coind->pos && !key)
|
||||
sprintf(data+strlen(data), "2321%sac", coind->pubkey);
|
||||
|
||||
else
|
||||
sprintf(data+strlen(data), "1976a914%s88ac", key? key: coind->script_pubkey);
|
||||
|
||||
// debuglog("pack tx %s\n", data+ol);
|
||||
// debuglog("pack tx %lld\n", amount);
|
||||
}
|
||||
|
||||
void coinbase_aux(YAAMP_JOB_TEMPLATE *templ, char *aux_script)
|
||||
{
|
||||
vector<string> hashlist = coind_aux_hashlist(templ->auxs, templ->auxs_size);
|
||||
while(hashlist.size() > 1)
|
||||
{
|
||||
vector<string> l;
|
||||
for(int i = 0; i < hashlist.size()/2; i++)
|
||||
{
|
||||
string s = hashlist[i*2] + hashlist[i*2+1];
|
||||
|
||||
char bin[YAAMP_HASHLEN_BIN*2];
|
||||
char out[YAAMP_HASHLEN_STR];
|
||||
|
||||
binlify((unsigned char *)bin, s.c_str());
|
||||
sha256_double_hash_hex(bin, out, YAAMP_HASHLEN_BIN*2);
|
||||
|
||||
l.push_back(out);
|
||||
}
|
||||
|
||||
hashlist = l;
|
||||
}
|
||||
|
||||
char merkle_hash[4*1024];
|
||||
memset(merkle_hash, 0, 4*1024);
|
||||
string_be(hashlist[0].c_str(), merkle_hash);
|
||||
|
||||
sprintf(aux_script+strlen(aux_script), "fabe6d6d%s%02x00000000000000", merkle_hash, templ->auxs_size);
|
||||
// debuglog("aux_script is %s\n", aux_script);
|
||||
}
|
||||
|
||||
void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value *json_result)
|
||||
{
|
||||
char eheight[64];
|
||||
ser_number(templ->height, eheight);
|
||||
|
||||
char etime[64];
|
||||
ser_number(time(NULL), etime);
|
||||
|
||||
char entime[64];
|
||||
memset(entime, 0, 64);
|
||||
|
||||
if(coind->pos)
|
||||
ser_string_be(templ->ntime, entime, 1);
|
||||
|
||||
char eversion1[64] = "01000000";
|
||||
|
||||
if(coind->txmessage)
|
||||
strcpy(eversion1, "02000000");
|
||||
|
||||
char script1[4*1024];
|
||||
sprintf(script1, "%s%s%s08", eheight, templ->flags, etime);
|
||||
|
||||
char script2[4*1024] = "7961616d702e636f6d00"; // yaamp.com
|
||||
if(!coind->pos && !coind->isaux && templ->auxs_size)
|
||||
coinbase_aux(templ, script2);
|
||||
|
||||
int script_len = strlen(script1)/2 + strlen(script2)/2 + 8;
|
||||
|
||||
sprintf(templ->coinb1,
|
||||
"%s%s010000000000000000000000000000000000000000000000000000000000000000ffffffff%02x%s", // 8+8+74+2 -> height
|
||||
eversion1, entime, script_len, script1);
|
||||
|
||||
sprintf(templ->coinb2, "%s00000000", script2);
|
||||
json_int_t available = templ->value;
|
||||
|
||||
if(strcmp(coind->symbol, "DRK") == 0 || strcmp(coind->symbol, "DASH") == 0)
|
||||
// if(strcmp(coind->symbol, "DRK") == 0)
|
||||
{
|
||||
char charity_payee[1024] = "";
|
||||
strcpy(charity_payee, json_get_string(json_result, "payee"));
|
||||
|
||||
json_int_t charity_amount = json_get_int(json_result, "payee_amount");
|
||||
bool charity_payments = json_get_bool(json_result, "masternode_payments");
|
||||
bool charity_enforce = json_get_bool(json_result, "enforce_masternode_payments");
|
||||
|
||||
if(charity_payments && charity_enforce)
|
||||
{
|
||||
strcat(templ->coinb2, "02");
|
||||
available -= charity_amount;
|
||||
|
||||
char script_payee[1024];
|
||||
base58_decode(charity_payee, script_payee);
|
||||
|
||||
job_pack_tx(coind, templ->coinb2, charity_amount, script_payee);
|
||||
}
|
||||
else
|
||||
strcat(templ->coinb2, "01");
|
||||
}
|
||||
|
||||
else
|
||||
strcat(templ->coinb2, "01");
|
||||
|
||||
job_pack_tx(coind, templ->coinb2, available, NULL);
|
||||
strcat(templ->coinb2, "00000000"); // locktime
|
||||
|
||||
coind->reward = (double)available/100000000*coind->reward_mul;
|
||||
// debuglog("coinbase %f\n", coind->reward);
|
||||
|
||||
// debuglog("new job: %x, %s, %s, %s\n", coind->templ->id, coind->templ->version, coind->templ->nbits, coind->templ->ntime);
|
||||
// debuglog("coinb1 %s\n", templ->coinb1);
|
||||
// debuglog("coinb2 %s\n", templ->coinb2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,113 +1,113 @@
|
|||
|
||||
#include "stratum.h"
|
||||
|
||||
bool coind_submitblock(YAAMP_COIND *coind, const char *block)
|
||||
{
|
||||
int paramlen = strlen(block);
|
||||
|
||||
char *params = (char *)malloc(paramlen+1024);
|
||||
if(!params) return false;
|
||||
|
||||
sprintf(params, "[\"%s\"]", block);
|
||||
json_value *json = rpc_call(&coind->rpc, "submitblock", params);
|
||||
|
||||
free(params);
|
||||
if(!json) return false;
|
||||
|
||||
json_value *json_error = json_get_object(json, "error");
|
||||
if(json_error && json_error->type != json_null)
|
||||
{
|
||||
const char *p = json_get_string(json_error, "message");
|
||||
if(p) stratumlog("ERROR %s %s\n", coind->name, p);
|
||||
|
||||
// job_reset();
|
||||
json_value_free(json);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
json_value *json_result = json_get_object(json, "result");
|
||||
|
||||
bool b = json_result && json_result->type == json_null;
|
||||
json_value_free(json);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
bool coind_submitblocktemplate(YAAMP_COIND *coind, const char *block)
|
||||
{
|
||||
int paramlen = strlen(block);
|
||||
|
||||
char *params = (char *)malloc(paramlen+1024);
|
||||
if(!params) return false;
|
||||
|
||||
sprintf(params, "[{\"mode\": \"submit\", \"data\": \"%s\"}]", block);
|
||||
json_value *json = rpc_call(&coind->rpc, "getblocktemplate", params);
|
||||
|
||||
free(params);
|
||||
if(!json) return false;
|
||||
|
||||
json_value *json_error = json_get_object(json, "error");
|
||||
if(json_error && json_error->type != json_null)
|
||||
{
|
||||
const char *p = json_get_string(json_error, "message");
|
||||
if(p) stratumlog("ERROR %s %s\n", coind->name, p);
|
||||
|
||||
// job_reset();
|
||||
json_value_free(json);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
json_value *json_result = json_get_object(json, "result");
|
||||
|
||||
bool b = json_result && json_result->type == json_null;
|
||||
json_value_free(json);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
bool coind_submit(YAAMP_COIND *coind, const char *block)
|
||||
{
|
||||
bool b;
|
||||
|
||||
if(coind->hassubmitblock)
|
||||
b = coind_submitblock(coind, block);
|
||||
else
|
||||
b = coind_submitblocktemplate(coind, block);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
bool coind_submitgetauxblock(YAAMP_COIND *coind, const char *hash, const char *block)
|
||||
{
|
||||
int paramlen = strlen(block);
|
||||
|
||||
char *params = (char *)malloc(paramlen+1024);
|
||||
if(!params) return false;
|
||||
|
||||
sprintf(params, "[\"%s\",\"%s\"]", hash, block);
|
||||
json_value *json = rpc_call(&coind->rpc, "getauxblock", params);
|
||||
|
||||
free(params);
|
||||
if(!json) return false;
|
||||
|
||||
json_value *json_error = json_get_object(json, "error");
|
||||
if(json_error && json_error->type != json_null)
|
||||
{
|
||||
const char *p = json_get_string(json_error, "message");
|
||||
if(p) stratumlog("ERROR %s %s\n", coind->name, p);
|
||||
|
||||
// job_reset();
|
||||
json_value_free(json);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
json_value *json_result = json_get_object(json, "result");
|
||||
bool b = json_result && json_result->type == json_boolean && json_result->u.boolean;
|
||||
|
||||
json_value_free(json);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
#include "stratum.h"
|
||||
|
||||
bool coind_submitblock(YAAMP_COIND *coind, const char *block)
|
||||
{
|
||||
int paramlen = strlen(block);
|
||||
|
||||
char *params = (char *)malloc(paramlen+1024);
|
||||
if(!params) return false;
|
||||
|
||||
sprintf(params, "[\"%s\"]", block);
|
||||
json_value *json = rpc_call(&coind->rpc, "submitblock", params);
|
||||
|
||||
free(params);
|
||||
if(!json) return false;
|
||||
|
||||
json_value *json_error = json_get_object(json, "error");
|
||||
if(json_error && json_error->type != json_null)
|
||||
{
|
||||
const char *p = json_get_string(json_error, "message");
|
||||
if(p) stratumlog("ERROR %s %s\n", coind->name, p);
|
||||
|
||||
// job_reset();
|
||||
json_value_free(json);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
json_value *json_result = json_get_object(json, "result");
|
||||
|
||||
bool b = json_result && json_result->type == json_null;
|
||||
json_value_free(json);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
bool coind_submitblocktemplate(YAAMP_COIND *coind, const char *block)
|
||||
{
|
||||
int paramlen = strlen(block);
|
||||
|
||||
char *params = (char *)malloc(paramlen+1024);
|
||||
if(!params) return false;
|
||||
|
||||
sprintf(params, "[{\"mode\": \"submit\", \"data\": \"%s\"}]", block);
|
||||
json_value *json = rpc_call(&coind->rpc, "getblocktemplate", params);
|
||||
|
||||
free(params);
|
||||
if(!json) return false;
|
||||
|
||||
json_value *json_error = json_get_object(json, "error");
|
||||
if(json_error && json_error->type != json_null)
|
||||
{
|
||||
const char *p = json_get_string(json_error, "message");
|
||||
if(p) stratumlog("ERROR %s %s\n", coind->name, p);
|
||||
|
||||
// job_reset();
|
||||
json_value_free(json);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
json_value *json_result = json_get_object(json, "result");
|
||||
|
||||
bool b = json_result && json_result->type == json_null;
|
||||
json_value_free(json);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
bool coind_submit(YAAMP_COIND *coind, const char *block)
|
||||
{
|
||||
bool b;
|
||||
|
||||
if(coind->hassubmitblock)
|
||||
b = coind_submitblock(coind, block);
|
||||
else
|
||||
b = coind_submitblocktemplate(coind, block);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
bool coind_submitgetauxblock(YAAMP_COIND *coind, const char *hash, const char *block)
|
||||
{
|
||||
int paramlen = strlen(block);
|
||||
|
||||
char *params = (char *)malloc(paramlen+1024);
|
||||
if(!params) return false;
|
||||
|
||||
sprintf(params, "[\"%s\",\"%s\"]", hash, block);
|
||||
json_value *json = rpc_call(&coind->rpc, "getauxblock", params);
|
||||
|
||||
free(params);
|
||||
if(!json) return false;
|
||||
|
||||
json_value *json_error = json_get_object(json, "error");
|
||||
if(json_error && json_error->type != json_null)
|
||||
{
|
||||
const char *p = json_get_string(json_error, "message");
|
||||
if(p) stratumlog("ERROR %s %s\n", coind->name, p);
|
||||
|
||||
// job_reset();
|
||||
json_value_free(json);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
json_value *json_result = json_get_object(json, "result");
|
||||
bool b = json_result && json_result->type == json_boolean && json_result->u.boolean;
|
||||
|
||||
json_value_free(json);
|
||||
return b;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
[TCP]
|
||||
server = yaamp.com
|
||||
port = 5033
|
||||
password = tu8tu5
|
||||
|
||||
[SQL]
|
||||
host = yaampdb
|
||||
database = yaamp
|
||||
username = root
|
||||
password = patofpaq
|
||||
|
||||
[STRATUM]
|
||||
algo = groestl
|
||||
difficulty = 0.1
|
||||
max_ttf = 200000000000000
|
||||
|
||||
[TCP]
|
||||
server = yaamp.com
|
||||
port = 5033
|
||||
password = tu8tu5
|
||||
|
||||
[SQL]
|
||||
host = yaampdb
|
||||
database = yaamp
|
||||
username = root
|
||||
password = patofpaq
|
||||
|
||||
[STRATUM]
|
||||
algo = groestl
|
||||
difficulty = 0.1
|
||||
max_ttf = 200000000000000
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
[TCP]
|
||||
server = yaamp.com
|
||||
port = 5133
|
||||
password = tu8tu5
|
||||
|
||||
[SQL]
|
||||
host = yaampdb
|
||||
database = yaamp
|
||||
username = root
|
||||
password = patofpaq
|
||||
|
||||
[STRATUM]
|
||||
algo = keccak
|
||||
difficulty = 0.1
|
||||
max_ttf = 200000000000000
|
||||
|
||||
[TCP]
|
||||
server = yaamp.com
|
||||
port = 5133
|
||||
password = tu8tu5
|
||||
|
||||
[SQL]
|
||||
host = yaampdb
|
||||
database = yaamp
|
||||
username = root
|
||||
password = patofpaq
|
||||
|
||||
[STRATUM]
|
||||
algo = keccak
|
||||
difficulty = 0.1
|
||||
max_ttf = 200000000000000
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
[TCP]
|
||||
server = yaamp.com
|
||||
port = 4033
|
||||
password = tu8tu5
|
||||
|
||||
[SQL]
|
||||
host = yaampdb
|
||||
database = yaamp
|
||||
username = root
|
||||
password = patofpaq
|
||||
|
||||
[STRATUM]
|
||||
algo = quark
|
||||
difficulty = 0.01
|
||||
max_ttf = 200000000000000
|
||||
|
||||
[TCP]
|
||||
server = yaamp.com
|
||||
port = 4033
|
||||
password = tu8tu5
|
||||
|
||||
[SQL]
|
||||
host = yaampdb
|
||||
database = yaamp
|
||||
username = root
|
||||
password = patofpaq
|
||||
|
||||
[STRATUM]
|
||||
algo = quark
|
||||
difficulty = 0.01
|
||||
max_ttf = 200000000000000
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
[TCP]
|
||||
server = yaamp.com
|
||||
port = 4733
|
||||
password = tu8tu5
|
||||
|
||||
[SQL]
|
||||
host = yaampdb
|
||||
database = yaamp
|
||||
username = root
|
||||
password = patofpaq
|
||||
|
||||
[STRATUM]
|
||||
algo = qubit
|
||||
difficulty = 0.01
|
||||
max_ttf = 200000000000000
|
||||
|
||||
[TCP]
|
||||
server = yaamp.com
|
||||
port = 4733
|
||||
password = tu8tu5
|
||||
|
||||
[SQL]
|
||||
host = yaampdb
|
||||
database = yaamp
|
||||
username = root
|
||||
password = patofpaq
|
||||
|
||||
[STRATUM]
|
||||
algo = qubit
|
||||
difficulty = 0.01
|
||||
max_ttf = 200000000000000
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
[TCP]
|
||||
server = yaamp.com
|
||||
port = 4933
|
||||
password = tu8tu5
|
||||
|
||||
[SQL]
|
||||
host = yaampdb
|
||||
database = yaamp
|
||||
username = root
|
||||
password = patofpaq
|
||||
|
||||
[STRATUM]
|
||||
algo = skein
|
||||
difficulty = 0.1
|
||||
max_ttf = 200000000000000
|
||||
|
||||
[TCP]
|
||||
server = yaamp.com
|
||||
port = 4933
|
||||
password = tu8tu5
|
||||
|
||||
[SQL]
|
||||
host = yaampdb
|
||||
database = yaamp
|
||||
username = root
|
||||
password = patofpaq
|
||||
|
||||
[STRATUM]
|
||||
algo = skein
|
||||
difficulty = 0.1
|
||||
max_ttf = 200000000000000
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
[TCP]
|
||||
server = yaamp.com
|
||||
port = 3933
|
||||
password = tu8tu5
|
||||
|
||||
[SQL]
|
||||
host = yaampdb
|
||||
database = yaamp
|
||||
username = root
|
||||
password = patofpaq
|
||||
|
||||
[STRATUM]
|
||||
algo = x14
|
||||
difficulty = 0.004
|
||||
max_ttf = 200000000000000
|
||||
|
||||
[TCP]
|
||||
server = yaamp.com
|
||||
port = 3933
|
||||
password = tu8tu5
|
||||
|
||||
[SQL]
|
||||
host = yaampdb
|
||||
database = yaamp
|
||||
username = root
|
||||
password = patofpaq
|
||||
|
||||
[STRATUM]
|
||||
algo = x14
|
||||
difficulty = 0.004
|
||||
max_ttf = 200000000000000
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
static void * mem_double(void * ptr, size_t size)
|
||||
{
|
||||
void * newptr ;
|
||||
|
||||
|
||||
newptr = calloc(2*size, 1);
|
||||
if (newptr==NULL) {
|
||||
return NULL ;
|
||||
|
@ -228,7 +228,7 @@ int dictionary_set(dictionary * d, const char * key, const char * val)
|
|||
unsigned hash ;
|
||||
|
||||
if (d==NULL || key==NULL) return -1 ;
|
||||
|
||||
|
||||
/* Compute hash for this key */
|
||||
hash = dictionary_hash(key) ;
|
||||
/* Find if value is already in dictionary */
|
||||
|
@ -371,7 +371,7 @@ int main(int argc, char *argv[])
|
|||
/* Allocate dictionary */
|
||||
printf("allocating...\n");
|
||||
d = dictionary_new(0);
|
||||
|
||||
|
||||
/* Set values in dictionary */
|
||||
printf("setting %d values...\n", NVALS);
|
||||
for (i=0 ; i<NVALS ; i++) {
|
||||
|
|
|
@ -67,7 +67,7 @@ void strstrip(char * s)
|
|||
|
||||
char *last = s + strlen(s);
|
||||
char *dest = s;
|
||||
|
||||
|
||||
while (isspace((int)*s) && *s) s++;
|
||||
while (last > s) {
|
||||
if (!isspace((int)*(last-1)))
|
||||
|
@ -283,7 +283,7 @@ int iniparser_getsecnkeys(dictionary * d, char * s)
|
|||
for (j=0 ; j<d->size ; j++) {
|
||||
if (d->key[j]==NULL)
|
||||
continue ;
|
||||
if (!strncmp(d->key[j], keym, secsize-1))
|
||||
if (!strncmp(d->key[j], keym, secsize-1))
|
||||
nkeys++;
|
||||
}
|
||||
free(keym);
|
||||
|
@ -301,7 +301,7 @@ int iniparser_getsecnkeys(dictionary * d, char * s)
|
|||
This function queries a dictionary and finds all keys in a given section.
|
||||
Each pointer in the returned char pointer-to-pointer is pointing to
|
||||
a string allocated in the dictionary; do not free or modify them.
|
||||
|
||||
|
||||
This function returns NULL in case of error.
|
||||
*/
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
@ -326,7 +326,7 @@ char ** iniparser_getseckeys(dictionary * d, char * s)
|
|||
secsize = (int)strlen(s) + 2;
|
||||
keym = malloc(secsize);
|
||||
snprintf(keym, secsize, "%s:", s);
|
||||
|
||||
|
||||
i = 0;
|
||||
|
||||
for (j=0 ; j<d->size ; j++) {
|
||||
|
@ -520,7 +520,7 @@ int iniparser_set(dictionary * ini, const char * entry, const char * val)
|
|||
{
|
||||
int result = 0;
|
||||
char *lc_entry = xstrdup(entry);
|
||||
strlwc(lc_entry);
|
||||
strlwc(lc_entry);
|
||||
result = dictionary_set(ini, lc_entry, val) ;
|
||||
free(lc_entry);
|
||||
return result;
|
||||
|
@ -560,7 +560,7 @@ static line_status iniparser_line(
|
|||
char ** section_out,
|
||||
char ** key_out,
|
||||
char ** value_out)
|
||||
{
|
||||
{
|
||||
line_status sta ;
|
||||
int len = line_size-1;
|
||||
char * line = malloc(line_size);
|
||||
|
@ -577,7 +577,7 @@ static line_status iniparser_line(
|
|||
|
||||
|
||||
strcpy(line, input_line);
|
||||
strstrip(line);
|
||||
strstrip(line);
|
||||
len = (int)strlen(line);
|
||||
|
||||
/* only allocate necessary space for key & val */
|
||||
|
@ -604,7 +604,7 @@ static line_status iniparser_line(
|
|||
sta = LINE_EMPTY ;
|
||||
} else if (line[0]=='#' || line[0]==';') {
|
||||
/* Comment line */
|
||||
sta = LINE_COMMENT ;
|
||||
sta = LINE_COMMENT ;
|
||||
} else if (line[0]=='[' && line[len-1]==']') {
|
||||
/* Section name */
|
||||
sscanf(line, "[%[^]]", key);
|
||||
|
@ -656,7 +656,7 @@ static line_status iniparser_line(
|
|||
sta = LINE_ERROR ;
|
||||
}
|
||||
|
||||
out:
|
||||
out:
|
||||
if (line) {
|
||||
free(line);
|
||||
line = NULL;
|
||||
|
@ -731,7 +731,7 @@ dictionary * iniparser_load(const char * ininame)
|
|||
val = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
lineno++ ;
|
||||
len = (int)strlen(line)-1;
|
||||
if (len==0)
|
||||
|
|
|
@ -83,13 +83,13 @@ int parse_ini_file(char * ini_name)
|
|||
printf("Wine:\n");
|
||||
s = iniparser_getstring(ini, "wine:grape", NULL);
|
||||
printf("Grape: [%s]\n", s ? s : "UNDEF");
|
||||
|
||||
|
||||
i = iniparser_getint(ini, "wine:year", -1);
|
||||
printf("Year: [%d]\n", i);
|
||||
|
||||
s = iniparser_getstring(ini, "wine:country", NULL);
|
||||
printf("Country: [%s]\n", s ? s : "UNDEF");
|
||||
|
||||
|
||||
d = iniparser_getdouble(ini, "wine:alcohol", -1.0);
|
||||
printf("Alcohol: [%g]\n", d);
|
||||
|
||||
|
|
|
@ -1,86 +1,86 @@
|
|||
|
||||
#include "stratum.h"
|
||||
|
||||
vector<string> merkle_steps(vector<string> input)
|
||||
{
|
||||
vector<string> L = input;
|
||||
vector<string> steps;
|
||||
vector<string> PreL;
|
||||
PreL.push_back("");
|
||||
|
||||
int Ll = L.size();
|
||||
while(Ll > 1)
|
||||
{
|
||||
steps.push_back(L[1]);
|
||||
|
||||
if(Ll % 2)
|
||||
L.push_back(L[L.size() - 1]);
|
||||
|
||||
vector<string> Ld;
|
||||
for(int i = 1; i < L.size()/2; i++)
|
||||
{
|
||||
string s = L[i*2] + L[i*2+1];
|
||||
|
||||
char bin[YAAMP_HASHLEN_BIN*2];
|
||||
char out[YAAMP_HASHLEN_STR];
|
||||
|
||||
binlify((unsigned char *)bin, s.c_str());
|
||||
sha256_double_hash_hex(bin, out, YAAMP_HASHLEN_BIN*2);
|
||||
|
||||
Ld.push_back(out);
|
||||
}
|
||||
|
||||
L = PreL;
|
||||
L.insert(L.end(), Ld.begin(), Ld.end());
|
||||
|
||||
Ll = L.size();
|
||||
}
|
||||
|
||||
return steps;
|
||||
}
|
||||
|
||||
string merkle_with_first(vector<string> steps, string f)
|
||||
{
|
||||
vector<string>::const_iterator i;
|
||||
for(i = steps.begin(); i != steps.end(); ++i)
|
||||
{
|
||||
string s = f + *i;
|
||||
|
||||
char bin[YAAMP_HASHLEN_BIN*2];
|
||||
char out[YAAMP_HASHLEN_STR];
|
||||
|
||||
binlify((unsigned char *)bin, s.c_str());
|
||||
sha256_double_hash_hex(bin, out, YAAMP_HASHLEN_BIN*2);
|
||||
|
||||
f = out;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
//def withFirst(self, f):
|
||||
// steps = self._steps
|
||||
// for s in steps:
|
||||
// f = doublesha(f + s)
|
||||
// return f
|
||||
|
||||
int test_merkle()
|
||||
{
|
||||
vector<string> hash;
|
||||
hash.push_back("");
|
||||
hash.push_back("999d2c8bb6bda0bf784d9ebeb631d711dbbbfe1bc006ea13d6ad0d6a2649a971");
|
||||
hash.push_back("3f92594d5a3d7b4df29d7dd7c46a0dac39a96e751ba0fc9bab5435ea5e22a19d");
|
||||
hash.push_back("a5633f03855f541d8e60a6340fc491d49709dc821f3acb571956a856637adcb6");
|
||||
hash.push_back("28d97c850eaf917a4c76c02474b05b70a197eaefb468d21c22ed110afe8ec9e0");
|
||||
|
||||
vector<string> res = merkle_steps(hash);
|
||||
string mr = merkle_with_first(res, "d43b669fb42cfa84695b844c0402d410213faa4f3e66cb7248f688ff19d5e5f7");
|
||||
|
||||
printf("mr: %s\n", mr.c_str()); // 82293f182d5db07d08acf334a5a907012bbb9990851557ac0ec028116081bd5a
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "stratum.h"
|
||||
|
||||
vector<string> merkle_steps(vector<string> input)
|
||||
{
|
||||
vector<string> L = input;
|
||||
vector<string> steps;
|
||||
vector<string> PreL;
|
||||
PreL.push_back("");
|
||||
|
||||
int Ll = L.size();
|
||||
while(Ll > 1)
|
||||
{
|
||||
steps.push_back(L[1]);
|
||||
|
||||
if(Ll % 2)
|
||||
L.push_back(L[L.size() - 1]);
|
||||
|
||||
vector<string> Ld;
|
||||
for(int i = 1; i < L.size()/2; i++)
|
||||
{
|
||||
string s = L[i*2] + L[i*2+1];
|
||||
|
||||
char bin[YAAMP_HASHLEN_BIN*2];
|
||||
char out[YAAMP_HASHLEN_STR];
|
||||
|
||||
binlify((unsigned char *)bin, s.c_str());
|
||||
sha256_double_hash_hex(bin, out, YAAMP_HASHLEN_BIN*2);
|
||||
|
||||
Ld.push_back(out);
|
||||
}
|
||||
|
||||
L = PreL;
|
||||
L.insert(L.end(), Ld.begin(), Ld.end());
|
||||
|
||||
Ll = L.size();
|
||||
}
|
||||
|
||||
return steps;
|
||||
}
|
||||
|
||||
string merkle_with_first(vector<string> steps, string f)
|
||||
{
|
||||
vector<string>::const_iterator i;
|
||||
for(i = steps.begin(); i != steps.end(); ++i)
|
||||
{
|
||||
string s = f + *i;
|
||||
|
||||
char bin[YAAMP_HASHLEN_BIN*2];
|
||||
char out[YAAMP_HASHLEN_STR];
|
||||
|
||||
binlify((unsigned char *)bin, s.c_str());
|
||||
sha256_double_hash_hex(bin, out, YAAMP_HASHLEN_BIN*2);
|
||||
|
||||
f = out;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
//def withFirst(self, f):
|
||||
// steps = self._steps
|
||||
// for s in steps:
|
||||
// f = doublesha(f + s)
|
||||
// return f
|
||||
|
||||
int test_merkle()
|
||||
{
|
||||
vector<string> hash;
|
||||
hash.push_back("");
|
||||
hash.push_back("999d2c8bb6bda0bf784d9ebeb631d711dbbbfe1bc006ea13d6ad0d6a2649a971");
|
||||
hash.push_back("3f92594d5a3d7b4df29d7dd7c46a0dac39a96e751ba0fc9bab5435ea5e22a19d");
|
||||
hash.push_back("a5633f03855f541d8e60a6340fc491d49709dc821f3acb571956a856637adcb6");
|
||||
hash.push_back("28d97c850eaf917a4c76c02474b05b70a197eaefb468d21c22ed110afe8ec9e0");
|
||||
|
||||
vector<string> res = merkle_steps(hash);
|
||||
string mr = merkle_with_first(res, "d43b669fb42cfa84695b844c0402d410213faa4f3e66cb7248f688ff19d5e5f7");
|
||||
|
||||
printf("mr: %s\n", mr.c_str()); // 82293f182d5db07d08acf334a5a907012bbb9990851557ac0ec028116081bd5a
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -26,10 +26,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -8,7 +8,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -16,10 +16,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -15,10 +15,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -13,10 +13,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -16,10 +16,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -13,10 +13,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -15,10 +15,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
@ -312,7 +312,7 @@ void sph_echo512_close(void *cc, void *dst);
|
|||
*/
|
||||
void sph_echo512_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -76,6 +76,6 @@ void sph_fugue512_addbits_and_close(
|
|||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -5,7 +5,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -13,10 +13,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -14,10 +14,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,322 +1,322 @@
|
|||
/* $Id: sph_hamsi.h 216 2010-06-08 09:46:57Z tp $ */
|
||||
/**
|
||||
* Hamsi interface. This code implements Hamsi with the recommended
|
||||
* parameters for SHA-3, with outputs of 224, 256, 384 and 512 bits.
|
||||
*
|
||||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* ===========================(LICENSE END)=============================
|
||||
*
|
||||
* @file sph_hamsi.h
|
||||
* @author Thomas Pornin <thomas.pornin@cryptolog.com>
|
||||
*/
|
||||
|
||||
#ifndef SPH_HAMSI_H__
|
||||
#define SPH_HAMSI_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include "sph_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Output size (in bits) for Hamsi-224.
|
||||
*/
|
||||
#define SPH_SIZE_hamsi224 224
|
||||
|
||||
/**
|
||||
* Output size (in bits) for Hamsi-256.
|
||||
*/
|
||||
#define SPH_SIZE_hamsi256 256
|
||||
|
||||
/**
|
||||
* Output size (in bits) for Hamsi-384.
|
||||
*/
|
||||
#define SPH_SIZE_hamsi384 384
|
||||
|
||||
/**
|
||||
* Output size (in bits) for Hamsi-512.
|
||||
*/
|
||||
#define SPH_SIZE_hamsi512 512
|
||||
|
||||
/**
|
||||
* This structure is a context for Hamsi-224 and Hamsi-256 computations:
|
||||
* it contains the intermediate values and some data from the last
|
||||
* entered block. Once a Hamsi computation has been performed, the
|
||||
* context can be reused for another computation.
|
||||
*
|
||||
* The contents of this structure are private. A running Hamsi
|
||||
* computation can be cloned by copying the context (e.g. with a simple
|
||||
* <code>memcpy()</code>).
|
||||
*/
|
||||
typedef struct {
|
||||
#ifndef DOXYGEN_IGNORE
|
||||
unsigned char partial[4];
|
||||
size_t partial_len;
|
||||
sph_u32 h[8];
|
||||
#if SPH_64
|
||||
sph_u64 count;
|
||||
#else
|
||||
sph_u32 count_high, count_low;
|
||||
#endif
|
||||
#endif
|
||||
} sph_hamsi_small_context;
|
||||
|
||||
/**
|
||||
* This structure is a context for Hamsi-224 computations. It is
|
||||
* identical to the common <code>sph_hamsi_small_context</code>.
|
||||
*/
|
||||
typedef sph_hamsi_small_context sph_hamsi224_context;
|
||||
|
||||
/**
|
||||
* This structure is a context for Hamsi-256 computations. It is
|
||||
* identical to the common <code>sph_hamsi_small_context</code>.
|
||||
*/
|
||||
typedef sph_hamsi_small_context sph_hamsi256_context;
|
||||
|
||||
/**
|
||||
* This structure is a context for Hamsi-384 and Hamsi-512 computations:
|
||||
* it contains the intermediate values and some data from the last
|
||||
* entered block. Once a Hamsi computation has been performed, the
|
||||
* context can be reused for another computation.
|
||||
*
|
||||
* The contents of this structure are private. A running Hamsi
|
||||
* computation can be cloned by copying the context (e.g. with a simple
|
||||
* <code>memcpy()</code>).
|
||||
*/
|
||||
typedef struct {
|
||||
#ifndef DOXYGEN_IGNORE
|
||||
unsigned char partial[8];
|
||||
size_t partial_len;
|
||||
sph_u32 h[16];
|
||||
#if SPH_64
|
||||
sph_u64 count;
|
||||
#else
|
||||
sph_u32 count_high, count_low;
|
||||
#endif
|
||||
#endif
|
||||
} sph_hamsi_big_context;
|
||||
|
||||
/**
|
||||
* This structure is a context for Hamsi-384 computations. It is
|
||||
* identical to the common <code>sph_hamsi_small_context</code>.
|
||||
*/
|
||||
typedef sph_hamsi_big_context sph_hamsi384_context;
|
||||
|
||||
/**
|
||||
* This structure is a context for Hamsi-512 computations. It is
|
||||
* identical to the common <code>sph_hamsi_small_context</code>.
|
||||
*/
|
||||
typedef sph_hamsi_big_context sph_hamsi512_context;
|
||||
|
||||
/**
|
||||
* Initialize a Hamsi-224 context. This process performs no memory allocation.
|
||||
*
|
||||
* @param cc the Hamsi-224 context (pointer to a
|
||||
* <code>sph_hamsi224_context</code>)
|
||||
*/
|
||||
void sph_hamsi224_init(void *cc);
|
||||
|
||||
/**
|
||||
* Process some data bytes. It is acceptable that <code>len</code> is zero
|
||||
* (in which case this function does nothing).
|
||||
*
|
||||
* @param cc the Hamsi-224 context
|
||||
* @param data the input data
|
||||
* @param len the input data length (in bytes)
|
||||
*/
|
||||
void sph_hamsi224(void *cc, const void *data, size_t len);
|
||||
|
||||
/**
|
||||
* Terminate the current Hamsi-224 computation and output the result into
|
||||
* the provided buffer. The destination buffer must be wide enough to
|
||||
* accomodate the result (28 bytes). The context is automatically
|
||||
* reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-224 context
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi224_close(void *cc, void *dst);
|
||||
|
||||
/**
|
||||
* Add a few additional bits (0 to 7) to the current computation, then
|
||||
* terminate it and output the result in the provided buffer, which must
|
||||
* be wide enough to accomodate the result (28 bytes). If bit number i
|
||||
* in <code>ub</code> has value 2^i, then the extra bits are those
|
||||
* numbered 7 downto 8-n (this is the big-endian convention at the byte
|
||||
* level). The context is automatically reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-224 context
|
||||
* @param ub the extra bits
|
||||
* @param n the number of extra bits (0 to 7)
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi224_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
/**
|
||||
* Initialize a Hamsi-256 context. This process performs no memory allocation.
|
||||
*
|
||||
* @param cc the Hamsi-256 context (pointer to a
|
||||
* <code>sph_hamsi256_context</code>)
|
||||
*/
|
||||
void sph_hamsi256_init(void *cc);
|
||||
|
||||
/**
|
||||
* Process some data bytes. It is acceptable that <code>len</code> is zero
|
||||
* (in which case this function does nothing).
|
||||
*
|
||||
* @param cc the Hamsi-256 context
|
||||
* @param data the input data
|
||||
* @param len the input data length (in bytes)
|
||||
*/
|
||||
void sph_hamsi256(void *cc, const void *data, size_t len);
|
||||
|
||||
/**
|
||||
* Terminate the current Hamsi-256 computation and output the result into
|
||||
* the provided buffer. The destination buffer must be wide enough to
|
||||
* accomodate the result (32 bytes). The context is automatically
|
||||
* reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-256 context
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi256_close(void *cc, void *dst);
|
||||
|
||||
/**
|
||||
* Add a few additional bits (0 to 7) to the current computation, then
|
||||
* terminate it and output the result in the provided buffer, which must
|
||||
* be wide enough to accomodate the result (32 bytes). If bit number i
|
||||
* in <code>ub</code> has value 2^i, then the extra bits are those
|
||||
* numbered 7 downto 8-n (this is the big-endian convention at the byte
|
||||
* level). The context is automatically reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-256 context
|
||||
* @param ub the extra bits
|
||||
* @param n the number of extra bits (0 to 7)
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi256_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
/**
|
||||
* Initialize a Hamsi-384 context. This process performs no memory allocation.
|
||||
*
|
||||
* @param cc the Hamsi-384 context (pointer to a
|
||||
* <code>sph_hamsi384_context</code>)
|
||||
*/
|
||||
void sph_hamsi384_init(void *cc);
|
||||
|
||||
/**
|
||||
* Process some data bytes. It is acceptable that <code>len</code> is zero
|
||||
* (in which case this function does nothing).
|
||||
*
|
||||
* @param cc the Hamsi-384 context
|
||||
* @param data the input data
|
||||
* @param len the input data length (in bytes)
|
||||
*/
|
||||
void sph_hamsi384(void *cc, const void *data, size_t len);
|
||||
|
||||
/**
|
||||
* Terminate the current Hamsi-384 computation and output the result into
|
||||
* the provided buffer. The destination buffer must be wide enough to
|
||||
* accomodate the result (48 bytes). The context is automatically
|
||||
* reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-384 context
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi384_close(void *cc, void *dst);
|
||||
|
||||
/**
|
||||
* Add a few additional bits (0 to 7) to the current computation, then
|
||||
* terminate it and output the result in the provided buffer, which must
|
||||
* be wide enough to accomodate the result (48 bytes). If bit number i
|
||||
* in <code>ub</code> has value 2^i, then the extra bits are those
|
||||
* numbered 7 downto 8-n (this is the big-endian convention at the byte
|
||||
* level). The context is automatically reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-384 context
|
||||
* @param ub the extra bits
|
||||
* @param n the number of extra bits (0 to 7)
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi384_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
/**
|
||||
* Initialize a Hamsi-512 context. This process performs no memory allocation.
|
||||
*
|
||||
* @param cc the Hamsi-512 context (pointer to a
|
||||
* <code>sph_hamsi512_context</code>)
|
||||
*/
|
||||
void sph_hamsi512_init(void *cc);
|
||||
|
||||
/**
|
||||
* Process some data bytes. It is acceptable that <code>len</code> is zero
|
||||
* (in which case this function does nothing).
|
||||
*
|
||||
* @param cc the Hamsi-512 context
|
||||
* @param data the input data
|
||||
* @param len the input data length (in bytes)
|
||||
*/
|
||||
void sph_hamsi512(void *cc, const void *data, size_t len);
|
||||
|
||||
/**
|
||||
* Terminate the current Hamsi-512 computation and output the result into
|
||||
* the provided buffer. The destination buffer must be wide enough to
|
||||
* accomodate the result (64 bytes). The context is automatically
|
||||
* reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-512 context
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi512_close(void *cc, void *dst);
|
||||
|
||||
/**
|
||||
* Add a few additional bits (0 to 7) to the current computation, then
|
||||
* terminate it and output the result in the provided buffer, which must
|
||||
* be wide enough to accomodate the result (64 bytes). If bit number i
|
||||
* in <code>ub</code> has value 2^i, then the extra bits are those
|
||||
* numbered 7 downto 8-n (this is the big-endian convention at the byte
|
||||
* level). The context is automatically reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-512 context
|
||||
* @param ub the extra bits
|
||||
* @param n the number of extra bits (0 to 7)
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi512_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* $Id: sph_hamsi.h 216 2010-06-08 09:46:57Z tp $ */
|
||||
/**
|
||||
* Hamsi interface. This code implements Hamsi with the recommended
|
||||
* parameters for SHA-3, with outputs of 224, 256, 384 and 512 bits.
|
||||
*
|
||||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* ===========================(LICENSE END)=============================
|
||||
*
|
||||
* @file sph_hamsi.h
|
||||
* @author Thomas Pornin <thomas.pornin@cryptolog.com>
|
||||
*/
|
||||
|
||||
#ifndef SPH_HAMSI_H__
|
||||
#define SPH_HAMSI_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include "sph_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Output size (in bits) for Hamsi-224.
|
||||
*/
|
||||
#define SPH_SIZE_hamsi224 224
|
||||
|
||||
/**
|
||||
* Output size (in bits) for Hamsi-256.
|
||||
*/
|
||||
#define SPH_SIZE_hamsi256 256
|
||||
|
||||
/**
|
||||
* Output size (in bits) for Hamsi-384.
|
||||
*/
|
||||
#define SPH_SIZE_hamsi384 384
|
||||
|
||||
/**
|
||||
* Output size (in bits) for Hamsi-512.
|
||||
*/
|
||||
#define SPH_SIZE_hamsi512 512
|
||||
|
||||
/**
|
||||
* This structure is a context for Hamsi-224 and Hamsi-256 computations:
|
||||
* it contains the intermediate values and some data from the last
|
||||
* entered block. Once a Hamsi computation has been performed, the
|
||||
* context can be reused for another computation.
|
||||
*
|
||||
* The contents of this structure are private. A running Hamsi
|
||||
* computation can be cloned by copying the context (e.g. with a simple
|
||||
* <code>memcpy()</code>).
|
||||
*/
|
||||
typedef struct {
|
||||
#ifndef DOXYGEN_IGNORE
|
||||
unsigned char partial[4];
|
||||
size_t partial_len;
|
||||
sph_u32 h[8];
|
||||
#if SPH_64
|
||||
sph_u64 count;
|
||||
#else
|
||||
sph_u32 count_high, count_low;
|
||||
#endif
|
||||
#endif
|
||||
} sph_hamsi_small_context;
|
||||
|
||||
/**
|
||||
* This structure is a context for Hamsi-224 computations. It is
|
||||
* identical to the common <code>sph_hamsi_small_context</code>.
|
||||
*/
|
||||
typedef sph_hamsi_small_context sph_hamsi224_context;
|
||||
|
||||
/**
|
||||
* This structure is a context for Hamsi-256 computations. It is
|
||||
* identical to the common <code>sph_hamsi_small_context</code>.
|
||||
*/
|
||||
typedef sph_hamsi_small_context sph_hamsi256_context;
|
||||
|
||||
/**
|
||||
* This structure is a context for Hamsi-384 and Hamsi-512 computations:
|
||||
* it contains the intermediate values and some data from the last
|
||||
* entered block. Once a Hamsi computation has been performed, the
|
||||
* context can be reused for another computation.
|
||||
*
|
||||
* The contents of this structure are private. A running Hamsi
|
||||
* computation can be cloned by copying the context (e.g. with a simple
|
||||
* <code>memcpy()</code>).
|
||||
*/
|
||||
typedef struct {
|
||||
#ifndef DOXYGEN_IGNORE
|
||||
unsigned char partial[8];
|
||||
size_t partial_len;
|
||||
sph_u32 h[16];
|
||||
#if SPH_64
|
||||
sph_u64 count;
|
||||
#else
|
||||
sph_u32 count_high, count_low;
|
||||
#endif
|
||||
#endif
|
||||
} sph_hamsi_big_context;
|
||||
|
||||
/**
|
||||
* This structure is a context for Hamsi-384 computations. It is
|
||||
* identical to the common <code>sph_hamsi_small_context</code>.
|
||||
*/
|
||||
typedef sph_hamsi_big_context sph_hamsi384_context;
|
||||
|
||||
/**
|
||||
* This structure is a context for Hamsi-512 computations. It is
|
||||
* identical to the common <code>sph_hamsi_small_context</code>.
|
||||
*/
|
||||
typedef sph_hamsi_big_context sph_hamsi512_context;
|
||||
|
||||
/**
|
||||
* Initialize a Hamsi-224 context. This process performs no memory allocation.
|
||||
*
|
||||
* @param cc the Hamsi-224 context (pointer to a
|
||||
* <code>sph_hamsi224_context</code>)
|
||||
*/
|
||||
void sph_hamsi224_init(void *cc);
|
||||
|
||||
/**
|
||||
* Process some data bytes. It is acceptable that <code>len</code> is zero
|
||||
* (in which case this function does nothing).
|
||||
*
|
||||
* @param cc the Hamsi-224 context
|
||||
* @param data the input data
|
||||
* @param len the input data length (in bytes)
|
||||
*/
|
||||
void sph_hamsi224(void *cc, const void *data, size_t len);
|
||||
|
||||
/**
|
||||
* Terminate the current Hamsi-224 computation and output the result into
|
||||
* the provided buffer. The destination buffer must be wide enough to
|
||||
* accomodate the result (28 bytes). The context is automatically
|
||||
* reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-224 context
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi224_close(void *cc, void *dst);
|
||||
|
||||
/**
|
||||
* Add a few additional bits (0 to 7) to the current computation, then
|
||||
* terminate it and output the result in the provided buffer, which must
|
||||
* be wide enough to accomodate the result (28 bytes). If bit number i
|
||||
* in <code>ub</code> has value 2^i, then the extra bits are those
|
||||
* numbered 7 downto 8-n (this is the big-endian convention at the byte
|
||||
* level). The context is automatically reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-224 context
|
||||
* @param ub the extra bits
|
||||
* @param n the number of extra bits (0 to 7)
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi224_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
/**
|
||||
* Initialize a Hamsi-256 context. This process performs no memory allocation.
|
||||
*
|
||||
* @param cc the Hamsi-256 context (pointer to a
|
||||
* <code>sph_hamsi256_context</code>)
|
||||
*/
|
||||
void sph_hamsi256_init(void *cc);
|
||||
|
||||
/**
|
||||
* Process some data bytes. It is acceptable that <code>len</code> is zero
|
||||
* (in which case this function does nothing).
|
||||
*
|
||||
* @param cc the Hamsi-256 context
|
||||
* @param data the input data
|
||||
* @param len the input data length (in bytes)
|
||||
*/
|
||||
void sph_hamsi256(void *cc, const void *data, size_t len);
|
||||
|
||||
/**
|
||||
* Terminate the current Hamsi-256 computation and output the result into
|
||||
* the provided buffer. The destination buffer must be wide enough to
|
||||
* accomodate the result (32 bytes). The context is automatically
|
||||
* reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-256 context
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi256_close(void *cc, void *dst);
|
||||
|
||||
/**
|
||||
* Add a few additional bits (0 to 7) to the current computation, then
|
||||
* terminate it and output the result in the provided buffer, which must
|
||||
* be wide enough to accomodate the result (32 bytes). If bit number i
|
||||
* in <code>ub</code> has value 2^i, then the extra bits are those
|
||||
* numbered 7 downto 8-n (this is the big-endian convention at the byte
|
||||
* level). The context is automatically reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-256 context
|
||||
* @param ub the extra bits
|
||||
* @param n the number of extra bits (0 to 7)
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi256_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
/**
|
||||
* Initialize a Hamsi-384 context. This process performs no memory allocation.
|
||||
*
|
||||
* @param cc the Hamsi-384 context (pointer to a
|
||||
* <code>sph_hamsi384_context</code>)
|
||||
*/
|
||||
void sph_hamsi384_init(void *cc);
|
||||
|
||||
/**
|
||||
* Process some data bytes. It is acceptable that <code>len</code> is zero
|
||||
* (in which case this function does nothing).
|
||||
*
|
||||
* @param cc the Hamsi-384 context
|
||||
* @param data the input data
|
||||
* @param len the input data length (in bytes)
|
||||
*/
|
||||
void sph_hamsi384(void *cc, const void *data, size_t len);
|
||||
|
||||
/**
|
||||
* Terminate the current Hamsi-384 computation and output the result into
|
||||
* the provided buffer. The destination buffer must be wide enough to
|
||||
* accomodate the result (48 bytes). The context is automatically
|
||||
* reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-384 context
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi384_close(void *cc, void *dst);
|
||||
|
||||
/**
|
||||
* Add a few additional bits (0 to 7) to the current computation, then
|
||||
* terminate it and output the result in the provided buffer, which must
|
||||
* be wide enough to accomodate the result (48 bytes). If bit number i
|
||||
* in <code>ub</code> has value 2^i, then the extra bits are those
|
||||
* numbered 7 downto 8-n (this is the big-endian convention at the byte
|
||||
* level). The context is automatically reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-384 context
|
||||
* @param ub the extra bits
|
||||
* @param n the number of extra bits (0 to 7)
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi384_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
/**
|
||||
* Initialize a Hamsi-512 context. This process performs no memory allocation.
|
||||
*
|
||||
* @param cc the Hamsi-512 context (pointer to a
|
||||
* <code>sph_hamsi512_context</code>)
|
||||
*/
|
||||
void sph_hamsi512_init(void *cc);
|
||||
|
||||
/**
|
||||
* Process some data bytes. It is acceptable that <code>len</code> is zero
|
||||
* (in which case this function does nothing).
|
||||
*
|
||||
* @param cc the Hamsi-512 context
|
||||
* @param data the input data
|
||||
* @param len the input data length (in bytes)
|
||||
*/
|
||||
void sph_hamsi512(void *cc, const void *data, size_t len);
|
||||
|
||||
/**
|
||||
* Terminate the current Hamsi-512 computation and output the result into
|
||||
* the provided buffer. The destination buffer must be wide enough to
|
||||
* accomodate the result (64 bytes). The context is automatically
|
||||
* reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-512 context
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi512_close(void *cc, void *dst);
|
||||
|
||||
/**
|
||||
* Add a few additional bits (0 to 7) to the current computation, then
|
||||
* terminate it and output the result in the provided buffer, which must
|
||||
* be wide enough to accomodate the result (64 bytes). If bit number i
|
||||
* in <code>ub</code> has value 2^i, then the extra bits are those
|
||||
* numbered 7 downto 8-n (this is the big-endian convention at the byte
|
||||
* level). The context is automatically reinitialized.
|
||||
*
|
||||
* @param cc the Hamsi-512 context
|
||||
* @param ub the extra bits
|
||||
* @param n the number of extra bits (0 to 7)
|
||||
* @param dst the destination buffer
|
||||
*/
|
||||
void sph_hamsi512_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -13,10 +13,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -15,10 +15,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -13,10 +13,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
@ -46,7 +46,7 @@ extern "C"{
|
|||
* SPH_KECCAK_UNROLL number of loops to unroll (0/undef for full unroll)
|
||||
* SPH_KECCAK_INTERLEAVE use bit-interleaving (32-bit type only)
|
||||
* SPH_KECCAK_NOCOPY do not copy the state into local variables
|
||||
*
|
||||
*
|
||||
* If there is no usable 64-bit type, the code automatically switches
|
||||
* back to the 32-bit implementation.
|
||||
*
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -15,10 +15,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -13,10 +13,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -15,10 +15,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
@ -288,9 +288,9 @@ void sph_luffa512_close(void *cc, void *dst);
|
|||
*/
|
||||
void sph_luffa512_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -13,10 +13,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
@ -99,7 +99,7 @@ static const sph_u32 IV512[] = {
|
|||
/*
|
||||
* This is the code needed to match the "reference implementation" as
|
||||
* published on Nov 23rd, 2009, instead of the published specification.
|
||||
*
|
||||
*
|
||||
|
||||
#define AES_BIG_ENDIAN 1
|
||||
#include "aes_helper.c"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -17,10 +17,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
@ -306,9 +306,9 @@ void sph_shavite512_close(void *cc, void *dst);
|
|||
*/
|
||||
void sph_shavite512_addbits_and_close(
|
||||
void *cc, unsigned ub, unsigned n, void *dst);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -13,10 +13,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -15,10 +15,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -13,10 +13,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -20,10 +20,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
||||
*
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
|
@ -26,10 +26,10 @@
|
|||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
|
|
|
@ -315,7 +315,7 @@ class YiiBase
|
|||
public static function autoload($className)
|
||||
{
|
||||
if(strstr($className, 'CAS_')) return false;
|
||||
|
||||
|
||||
// use include so that the error PHP file may appear
|
||||
if(isset(self::$_coreClasses[$className]))
|
||||
include(YII_PATH.self::$_coreClasses[$className]);
|
||||
|
@ -329,7 +329,7 @@ class YiiBase
|
|||
include($classfile);
|
||||
return class_exists($className,false) || interface_exists($className,false);
|
||||
}
|
||||
|
||||
|
||||
include($className.'.php');
|
||||
return class_exists($className,false) || interface_exists($className,false);
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ abstract class CApplication extends CModule
|
|||
public function __construct($config=null)
|
||||
{
|
||||
Yii::setApplication($this);
|
||||
|
||||
|
||||
// set basePath at early as possible to avoid trouble
|
||||
if(is_string($config))
|
||||
$config=require($config);
|
||||
|
|
|
@ -423,7 +423,7 @@ abstract class CModel extends CComponent implements IteratorAggregate, ArrayAcce
|
|||
throw new CException(Yii::t('yii','{class} has an invalid validation rule. The rule must specify attributes to be validated and the validator name.',
|
||||
array('{class}'=>get_class($this))));
|
||||
}
|
||||
|
||||
|
||||
// debuglog(" good");
|
||||
return $validators;
|
||||
}
|
||||
|
|
|
@ -1,200 +1,200 @@
|
|||
<?php
|
||||
/**
|
||||
* CConsoleApplication class file.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright 2008-2013 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
/**
|
||||
* CConsoleApplication represents a console application.
|
||||
*
|
||||
* CConsoleApplication extends {@link CApplication} by providing functionalities
|
||||
* specific to console requests. In particular, it deals with console requests
|
||||
* through a command-based approach:
|
||||
* <ul>
|
||||
* <li>A console application consists of one or several possible user commands;</li>
|
||||
* <li>Each user command is implemented as a class extending {@link CConsoleCommand};</li>
|
||||
* <li>User specifies which command to run on the command line;</li>
|
||||
* <li>The command processes the user request with the specified parameters.</li>
|
||||
* </ul>
|
||||
*
|
||||
* The command classes reside in the directory {@link getCommandPath commandPath}.
|
||||
* The name of the class follows the pattern: <command-name>Command, and its
|
||||
* file name is the same as the class name. For example, the 'ShellCommand' class defines
|
||||
* a 'shell' command and the class file name is 'ShellCommand.php'.
|
||||
*
|
||||
* To run the console application, enter the following on the command line:
|
||||
* <pre>
|
||||
* php path/to/entry_script.php <command name> [param 1] [param 2] ...
|
||||
* </pre>
|
||||
*
|
||||
* You may use the following to see help instructions about a command:
|
||||
* <pre>
|
||||
* php path/to/entry_script.php help <command name>
|
||||
* </pre>
|
||||
*
|
||||
* @property string $commandPath The directory that contains the command classes. Defaults to 'protected/commands'.
|
||||
* @property CConsoleCommandRunner $commandRunner The command runner.
|
||||
* @property CConsoleCommand $command The currently active command.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @package system.console
|
||||
* @since 1.0
|
||||
*/
|
||||
class CConsoleApplication extends CApplication
|
||||
{
|
||||
/**
|
||||
* @var array mapping from command name to command configurations.
|
||||
* Each command configuration can be either a string or an array.
|
||||
* If the former, the string should be the file path of the command class.
|
||||
* If the latter, the array must contain a 'class' element which specifies
|
||||
* the command's class name or {@link YiiBase::getPathOfAlias class path alias}.
|
||||
* The rest name-value pairs in the array are used to initialize
|
||||
* the corresponding command properties. For example,
|
||||
* <pre>
|
||||
* array(
|
||||
* 'email'=>array(
|
||||
* 'class'=>'path.to.Mailer',
|
||||
* 'interval'=>3600,
|
||||
* ),
|
||||
* 'log'=>'path/to/LoggerCommand.php',
|
||||
* )
|
||||
* </pre>
|
||||
*/
|
||||
public $commandMap=array();
|
||||
|
||||
private $_commandPath;
|
||||
private $_runner;
|
||||
|
||||
/**
|
||||
* Initializes the application by creating the command runner.
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
parent::init();
|
||||
if(!isset($_SERVER['argv'])) // || strncasecmp(php_sapi_name(),'cli',3))
|
||||
die('This script must be run from the command line.');
|
||||
$this->_runner=$this->createCommandRunner();
|
||||
$this->_runner->commands=$this->commandMap;
|
||||
$this->_runner->addCommands($this->getCommandPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the user request.
|
||||
* This method uses a console command runner to handle the particular user command.
|
||||
* Since version 1.1.11 this method will exit application with an exit code if one is returned by the user command.
|
||||
*/
|
||||
public function processRequest()
|
||||
{
|
||||
$exitCode=$this->_runner->run($_SERVER['argv']);
|
||||
if(is_int($exitCode))
|
||||
$this->end($exitCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the command runner instance.
|
||||
* @return CConsoleCommandRunner the command runner
|
||||
*/
|
||||
protected function createCommandRunner()
|
||||
{
|
||||
return new CConsoleCommandRunner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the captured PHP error.
|
||||
* This method displays the error in console mode when there is
|
||||
* no active error handler.
|
||||
* @param integer $code error code
|
||||
* @param string $message error message
|
||||
* @param string $file error file
|
||||
* @param string $line error line
|
||||
*/
|
||||
public function displayError($code,$message,$file,$line)
|
||||
{
|
||||
echo "PHP Error[$code]: $message\n";
|
||||
echo " in file $file at line $line\n";
|
||||
$trace=debug_backtrace();
|
||||
// skip the first 4 stacks as they do not tell the error position
|
||||
if(count($trace)>4)
|
||||
$trace=array_slice($trace,4);
|
||||
foreach($trace as $i=>$t)
|
||||
{
|
||||
if(!isset($t['file']))
|
||||
$t['file']='unknown';
|
||||
if(!isset($t['line']))
|
||||
$t['line']=0;
|
||||
if(!isset($t['function']))
|
||||
$t['function']='unknown';
|
||||
echo "#$i {$t['file']}({$t['line']}): ";
|
||||
if(isset($t['object']) && is_object($t['object']))
|
||||
echo get_class($t['object']).'->';
|
||||
echo "{$t['function']}()\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the uncaught PHP exception.
|
||||
* This method displays the exception in console mode when there is
|
||||
* no active error handler.
|
||||
* @param Exception $exception the uncaught exception
|
||||
*/
|
||||
public function displayException($exception)
|
||||
{
|
||||
echo $exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the directory that contains the command classes. Defaults to 'protected/commands'.
|
||||
*/
|
||||
public function getCommandPath()
|
||||
{
|
||||
$applicationCommandPath = $this->getBasePath().DIRECTORY_SEPARATOR.'commands';
|
||||
if($this->_commandPath===null && file_exists($applicationCommandPath))
|
||||
$this->setCommandPath($applicationCommandPath);
|
||||
return $this->_commandPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value the directory that contains the command classes.
|
||||
* @throws CException if the directory is invalid
|
||||
*/
|
||||
public function setCommandPath($value)
|
||||
{
|
||||
if(($this->_commandPath=realpath($value))===false || !is_dir($this->_commandPath))
|
||||
throw new CException(Yii::t('yii','The command path "{path}" is not a valid directory.',
|
||||
array('{path}'=>$value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command runner.
|
||||
* @return CConsoleCommandRunner the command runner.
|
||||
*/
|
||||
public function getCommandRunner()
|
||||
{
|
||||
return $this->_runner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently running command.
|
||||
* This is shortcut method for {@link CConsoleCommandRunner::getCommand()}.
|
||||
* @return CConsoleCommand|null the currently active command.
|
||||
* @since 1.1.14
|
||||
*/
|
||||
public function getCommand()
|
||||
{
|
||||
return $this->getCommandRunner()->getCommand();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is shortcut method for {@link CConsoleCommandRunner::setCommand()}.
|
||||
* @param CConsoleCommand $value the currently active command.
|
||||
* @since 1.1.14
|
||||
*/
|
||||
public function setCommand($value)
|
||||
{
|
||||
$this->getCommandRunner()->setCommand($value);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* CConsoleApplication class file.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright 2008-2013 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
/**
|
||||
* CConsoleApplication represents a console application.
|
||||
*
|
||||
* CConsoleApplication extends {@link CApplication} by providing functionalities
|
||||
* specific to console requests. In particular, it deals with console requests
|
||||
* through a command-based approach:
|
||||
* <ul>
|
||||
* <li>A console application consists of one or several possible user commands;</li>
|
||||
* <li>Each user command is implemented as a class extending {@link CConsoleCommand};</li>
|
||||
* <li>User specifies which command to run on the command line;</li>
|
||||
* <li>The command processes the user request with the specified parameters.</li>
|
||||
* </ul>
|
||||
*
|
||||
* The command classes reside in the directory {@link getCommandPath commandPath}.
|
||||
* The name of the class follows the pattern: <command-name>Command, and its
|
||||
* file name is the same as the class name. For example, the 'ShellCommand' class defines
|
||||
* a 'shell' command and the class file name is 'ShellCommand.php'.
|
||||
*
|
||||
* To run the console application, enter the following on the command line:
|
||||
* <pre>
|
||||
* php path/to/entry_script.php <command name> [param 1] [param 2] ...
|
||||
* </pre>
|
||||
*
|
||||
* You may use the following to see help instructions about a command:
|
||||
* <pre>
|
||||
* php path/to/entry_script.php help <command name>
|
||||
* </pre>
|
||||
*
|
||||
* @property string $commandPath The directory that contains the command classes. Defaults to 'protected/commands'.
|
||||
* @property CConsoleCommandRunner $commandRunner The command runner.
|
||||
* @property CConsoleCommand $command The currently active command.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @package system.console
|
||||
* @since 1.0
|
||||
*/
|
||||
class CConsoleApplication extends CApplication
|
||||
{
|
||||
/**
|
||||
* @var array mapping from command name to command configurations.
|
||||
* Each command configuration can be either a string or an array.
|
||||
* If the former, the string should be the file path of the command class.
|
||||
* If the latter, the array must contain a 'class' element which specifies
|
||||
* the command's class name or {@link YiiBase::getPathOfAlias class path alias}.
|
||||
* The rest name-value pairs in the array are used to initialize
|
||||
* the corresponding command properties. For example,
|
||||
* <pre>
|
||||
* array(
|
||||
* 'email'=>array(
|
||||
* 'class'=>'path.to.Mailer',
|
||||
* 'interval'=>3600,
|
||||
* ),
|
||||
* 'log'=>'path/to/LoggerCommand.php',
|
||||
* )
|
||||
* </pre>
|
||||
*/
|
||||
public $commandMap=array();
|
||||
|
||||
private $_commandPath;
|
||||
private $_runner;
|
||||
|
||||
/**
|
||||
* Initializes the application by creating the command runner.
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
parent::init();
|
||||
if(!isset($_SERVER['argv'])) // || strncasecmp(php_sapi_name(),'cli',3))
|
||||
die('This script must be run from the command line.');
|
||||
$this->_runner=$this->createCommandRunner();
|
||||
$this->_runner->commands=$this->commandMap;
|
||||
$this->_runner->addCommands($this->getCommandPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the user request.
|
||||
* This method uses a console command runner to handle the particular user command.
|
||||
* Since version 1.1.11 this method will exit application with an exit code if one is returned by the user command.
|
||||
*/
|
||||
public function processRequest()
|
||||
{
|
||||
$exitCode=$this->_runner->run($_SERVER['argv']);
|
||||
if(is_int($exitCode))
|
||||
$this->end($exitCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the command runner instance.
|
||||
* @return CConsoleCommandRunner the command runner
|
||||
*/
|
||||
protected function createCommandRunner()
|
||||
{
|
||||
return new CConsoleCommandRunner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the captured PHP error.
|
||||
* This method displays the error in console mode when there is
|
||||
* no active error handler.
|
||||
* @param integer $code error code
|
||||
* @param string $message error message
|
||||
* @param string $file error file
|
||||
* @param string $line error line
|
||||
*/
|
||||
public function displayError($code,$message,$file,$line)
|
||||
{
|
||||
echo "PHP Error[$code]: $message\n";
|
||||
echo " in file $file at line $line\n";
|
||||
$trace=debug_backtrace();
|
||||
// skip the first 4 stacks as they do not tell the error position
|
||||
if(count($trace)>4)
|
||||
$trace=array_slice($trace,4);
|
||||
foreach($trace as $i=>$t)
|
||||
{
|
||||
if(!isset($t['file']))
|
||||
$t['file']='unknown';
|
||||
if(!isset($t['line']))
|
||||
$t['line']=0;
|
||||
if(!isset($t['function']))
|
||||
$t['function']='unknown';
|
||||
echo "#$i {$t['file']}({$t['line']}): ";
|
||||
if(isset($t['object']) && is_object($t['object']))
|
||||
echo get_class($t['object']).'->';
|
||||
echo "{$t['function']}()\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the uncaught PHP exception.
|
||||
* This method displays the exception in console mode when there is
|
||||
* no active error handler.
|
||||
* @param Exception $exception the uncaught exception
|
||||
*/
|
||||
public function displayException($exception)
|
||||
{
|
||||
echo $exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the directory that contains the command classes. Defaults to 'protected/commands'.
|
||||
*/
|
||||
public function getCommandPath()
|
||||
{
|
||||
$applicationCommandPath = $this->getBasePath().DIRECTORY_SEPARATOR.'commands';
|
||||
if($this->_commandPath===null && file_exists($applicationCommandPath))
|
||||
$this->setCommandPath($applicationCommandPath);
|
||||
return $this->_commandPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value the directory that contains the command classes.
|
||||
* @throws CException if the directory is invalid
|
||||
*/
|
||||
public function setCommandPath($value)
|
||||
{
|
||||
if(($this->_commandPath=realpath($value))===false || !is_dir($this->_commandPath))
|
||||
throw new CException(Yii::t('yii','The command path "{path}" is not a valid directory.',
|
||||
array('{path}'=>$value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command runner.
|
||||
* @return CConsoleCommandRunner the command runner.
|
||||
*/
|
||||
public function getCommandRunner()
|
||||
{
|
||||
return $this->_runner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently running command.
|
||||
* This is shortcut method for {@link CConsoleCommandRunner::getCommand()}.
|
||||
* @return CConsoleCommand|null the currently active command.
|
||||
* @since 1.1.14
|
||||
*/
|
||||
public function getCommand()
|
||||
{
|
||||
return $this->getCommandRunner()->getCommand();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is shortcut method for {@link CConsoleCommandRunner::setCommand()}.
|
||||
* @param CConsoleCommand $value the currently active command.
|
||||
* @since 1.1.14
|
||||
*/
|
||||
public function setCommand($value)
|
||||
{
|
||||
$this->getCommandRunner()->setCommand($value);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,53 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* CConsoleCommandBehavior class file.
|
||||
*
|
||||
* @author Evgeny Blinov <e.a.blinov@gmail.com>
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright 2008-2013 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
/**
|
||||
* CConsoleCommandBehavior is a base class for behaviors that are attached to a console command component.
|
||||
*
|
||||
* @property CConsoleCommand $owner The owner model that this behavior is attached to.
|
||||
*
|
||||
* @author Evgeny Blinov <e.a.blinov@gmail.com>
|
||||
* @package system.console
|
||||
* @since 1.1.11
|
||||
*/
|
||||
class CConsoleCommandBehavior extends CBehavior
|
||||
{
|
||||
/**
|
||||
* Declares events and the corresponding event handler methods.
|
||||
* The default implementation returns 'onAfterConstruct', 'onBeforeValidate' and 'onAfterValidate' events and handlers.
|
||||
* If you override this method, make sure you merge the parent result to the return value.
|
||||
* @return array events (array keys) and the corresponding event handler methods (array values).
|
||||
* @see CBehavior::events
|
||||
*/
|
||||
public function events()
|
||||
{
|
||||
return array(
|
||||
'onBeforeAction' => 'beforeAction',
|
||||
'onAfterAction' => 'afterAction'
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Responds to {@link CConsoleCommand::onBeforeAction} event.
|
||||
* Override this method and make it public if you want to handle the corresponding event of the {@link CBehavior::owner owner}.
|
||||
* @param CConsoleCommandEvent $event event parameter
|
||||
*/
|
||||
protected function beforeAction($event)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds to {@link CConsoleCommand::onAfterAction} event.
|
||||
* Override this method and make it public if you want to handle the corresponding event of the {@link CBehavior::owner owner}.
|
||||
* @param CConsoleCommandEvent $event event parameter
|
||||
*/
|
||||
protected function afterAction($event)
|
||||
{
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* CConsoleCommandBehavior class file.
|
||||
*
|
||||
* @author Evgeny Blinov <e.a.blinov@gmail.com>
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright 2008-2013 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
/**
|
||||
* CConsoleCommandBehavior is a base class for behaviors that are attached to a console command component.
|
||||
*
|
||||
* @property CConsoleCommand $owner The owner model that this behavior is attached to.
|
||||
*
|
||||
* @author Evgeny Blinov <e.a.blinov@gmail.com>
|
||||
* @package system.console
|
||||
* @since 1.1.11
|
||||
*/
|
||||
class CConsoleCommandBehavior extends CBehavior
|
||||
{
|
||||
/**
|
||||
* Declares events and the corresponding event handler methods.
|
||||
* The default implementation returns 'onAfterConstruct', 'onBeforeValidate' and 'onAfterValidate' events and handlers.
|
||||
* If you override this method, make sure you merge the parent result to the return value.
|
||||
* @return array events (array keys) and the corresponding event handler methods (array values).
|
||||
* @see CBehavior::events
|
||||
*/
|
||||
public function events()
|
||||
{
|
||||
return array(
|
||||
'onBeforeAction' => 'beforeAction',
|
||||
'onAfterAction' => 'afterAction'
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Responds to {@link CConsoleCommand::onBeforeAction} event.
|
||||
* Override this method and make it public if you want to handle the corresponding event of the {@link CBehavior::owner owner}.
|
||||
* @param CConsoleCommandEvent $event event parameter
|
||||
*/
|
||||
protected function beforeAction($event)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds to {@link CConsoleCommand::onAfterAction} event.
|
||||
* Override this method and make it public if you want to handle the corresponding event of the {@link CBehavior::owner owner}.
|
||||
* @param CConsoleCommandEvent $event event parameter
|
||||
*/
|
||||
protected function afterAction($event)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,52 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* CConsoleCommandEvent class file.
|
||||
*
|
||||
* @author Evgeny Blinov <e.a.blinov@gmail.com>
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright 2008-2013 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
/**
|
||||
* CConsoleCommandEvent class.
|
||||
*
|
||||
* CConsoleCommandEvent represents the event parameters needed by events raised by a console command.
|
||||
*
|
||||
* @author Evgeny Blinov <e.a.blinov@gmail.com>
|
||||
* @package system.console
|
||||
* @since 1.1.11
|
||||
*/
|
||||
class CConsoleCommandEvent extends CEvent
|
||||
{
|
||||
/**
|
||||
* @var string the action name
|
||||
*/
|
||||
public $action;
|
||||
/**
|
||||
* @var boolean whether the action should be executed.
|
||||
* If this property is set true by the event handler, the console command action will quit after handling this event.
|
||||
* If false, which is the default, the normal execution cycles will continue, including performing the action and calling
|
||||
* {@link CConsoleCommand::afterAction}.
|
||||
*/
|
||||
public $stopCommand=false;
|
||||
/**
|
||||
* @var integer exit code of application.
|
||||
* This property is available in {@link CConsoleCommand::onAfterAction} event and will be set to the exit code
|
||||
* returned by the console command action. You can set it to change application exit code.
|
||||
*/
|
||||
public $exitCode;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param mixed $sender sender of the event
|
||||
* @param string $params the parameters to be passed to the action method.
|
||||
* @param string $action the action name
|
||||
* @param integer $exitCode the application exit code
|
||||
*/
|
||||
public function __construct($sender=null,$params=null,$action=null,$exitCode=0){
|
||||
parent::__construct($sender,$params);
|
||||
$this->action=$action;
|
||||
$this->exitCode=$exitCode;
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* CConsoleCommandEvent class file.
|
||||
*
|
||||
* @author Evgeny Blinov <e.a.blinov@gmail.com>
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright 2008-2013 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
/**
|
||||
* CConsoleCommandEvent class.
|
||||
*
|
||||
* CConsoleCommandEvent represents the event parameters needed by events raised by a console command.
|
||||
*
|
||||
* @author Evgeny Blinov <e.a.blinov@gmail.com>
|
||||
* @package system.console
|
||||
* @since 1.1.11
|
||||
*/
|
||||
class CConsoleCommandEvent extends CEvent
|
||||
{
|
||||
/**
|
||||
* @var string the action name
|
||||
*/
|
||||
public $action;
|
||||
/**
|
||||
* @var boolean whether the action should be executed.
|
||||
* If this property is set true by the event handler, the console command action will quit after handling this event.
|
||||
* If false, which is the default, the normal execution cycles will continue, including performing the action and calling
|
||||
* {@link CConsoleCommand::afterAction}.
|
||||
*/
|
||||
public $stopCommand=false;
|
||||
/**
|
||||
* @var integer exit code of application.
|
||||
* This property is available in {@link CConsoleCommand::onAfterAction} event and will be set to the exit code
|
||||
* returned by the console command action. You can set it to change application exit code.
|
||||
*/
|
||||
public $exitCode;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param mixed $sender sender of the event
|
||||
* @param string $params the parameters to be passed to the action method.
|
||||
* @param string $action the action name
|
||||
* @param integer $exitCode the application exit code
|
||||
*/
|
||||
public function __construct($sender=null,$params=null,$action=null,$exitCode=0){
|
||||
parent::__construct($sender,$params);
|
||||
$this->action=$action;
|
||||
$this->exitCode=$exitCode;
|
||||
}
|
||||
}
|
|
@ -1,180 +1,180 @@
|
|||
<?php
|
||||
/**
|
||||
* CConsoleCommandRunner class file.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright 2008-2013 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
/**
|
||||
* CConsoleCommandRunner manages commands and executes the requested command.
|
||||
*
|
||||
* @property string $scriptName The entry script name.
|
||||
* @property CConsoleCommand $command The currently active command.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @package system.console
|
||||
* @since 1.0
|
||||
*/
|
||||
class CConsoleCommandRunner extends CComponent
|
||||
{
|
||||
/**
|
||||
* @var array list of all available commands (command name=>command configuration).
|
||||
* Each command configuration can be either a string or an array.
|
||||
* If the former, the string should be the class name or
|
||||
* {@link YiiBase::getPathOfAlias class path alias} of the command.
|
||||
* If the latter, the array must contain a 'class' element which specifies
|
||||
* the command's class name or {@link YiiBase::getPathOfAlias class path alias}.
|
||||
* The rest name-value pairs in the array are used to initialize
|
||||
* the corresponding command properties. For example,
|
||||
* <pre>
|
||||
* array(
|
||||
* 'email'=>array(
|
||||
* 'class'=>'path.to.Mailer',
|
||||
* 'interval'=>3600,
|
||||
* ),
|
||||
* 'log'=>'path.to.LoggerCommand',
|
||||
* )
|
||||
* </pre>
|
||||
*/
|
||||
public $commands=array();
|
||||
|
||||
private $_scriptName;
|
||||
private $_command;
|
||||
|
||||
/**
|
||||
* Executes the requested command.
|
||||
* @param array $args list of user supplied parameters (including the entry script name and the command name).
|
||||
* @return integer|null application exit code returned by the command.
|
||||
* if null is returned, application will not exit explicitly. See also {@link CConsoleApplication::processRequest()}.
|
||||
* (return value is available since version 1.1.11)
|
||||
*/
|
||||
public function run($args)
|
||||
{
|
||||
$this->_scriptName=$args[0];
|
||||
array_shift($args);
|
||||
if(isset($args[0]))
|
||||
{
|
||||
$name=$args[0];
|
||||
array_shift($args);
|
||||
}
|
||||
else
|
||||
$name='help';
|
||||
|
||||
$oldCommand=$this->_command;
|
||||
if(($command=$this->createCommand($name))===null)
|
||||
$command=$this->createCommand('help');
|
||||
$this->_command=$command;
|
||||
$command->init();
|
||||
$exitCode=$command->run($args);
|
||||
$this->_command=$oldCommand;
|
||||
return $exitCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the entry script name
|
||||
*/
|
||||
public function getScriptName()
|
||||
{
|
||||
return $this->_scriptName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently running command.
|
||||
* @return CConsoleCommand|null the currently active command.
|
||||
* @since 1.1.14
|
||||
*/
|
||||
public function getCommand()
|
||||
{
|
||||
return $this->_command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CConsoleCommand $value the currently active command.
|
||||
* @since 1.1.14
|
||||
*/
|
||||
public function setCommand($value)
|
||||
{
|
||||
$this->_command=$value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for commands under the specified directory.
|
||||
* @param string $path the directory containing the command class files.
|
||||
* @return array list of commands (command name=>command class file)
|
||||
*/
|
||||
public function findCommands($path)
|
||||
{
|
||||
if(($dir=@opendir($path))===false)
|
||||
return array();
|
||||
$commands=array();
|
||||
while(($name=readdir($dir))!==false)
|
||||
{
|
||||
$file=$path.DIRECTORY_SEPARATOR.$name;
|
||||
if(!strcasecmp(substr($name,-11),'Command.php') && is_file($file))
|
||||
$commands[strtolower(substr($name,0,-11))]=$file;
|
||||
}
|
||||
closedir($dir);
|
||||
return $commands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds commands from the specified command path.
|
||||
* If a command already exists, the new one will be ignored.
|
||||
* @param string $path the alias of the directory containing the command class files.
|
||||
*/
|
||||
public function addCommands($path)
|
||||
{
|
||||
if(($commands=$this->findCommands($path))!==array())
|
||||
{
|
||||
foreach($commands as $name=>$file)
|
||||
{
|
||||
if(!isset($this->commands[$name]))
|
||||
$this->commands[$name]=$file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name command name (case-insensitive)
|
||||
* @return CConsoleCommand the command object. Null if the name is invalid.
|
||||
*/
|
||||
public function createCommand($name)
|
||||
{
|
||||
$name=strtolower($name);
|
||||
|
||||
$command=null;
|
||||
if(isset($this->commands[$name]))
|
||||
$command=$this->commands[$name];
|
||||
else
|
||||
{
|
||||
$commands=array_change_key_case($this->commands);
|
||||
if(isset($commands[$name]))
|
||||
$command=$commands[$name];
|
||||
}
|
||||
|
||||
if($command!==null)
|
||||
{
|
||||
if(is_string($command)) // class file path or alias
|
||||
{
|
||||
if(strpos($command,'/')!==false || strpos($command,'\\')!==false)
|
||||
{
|
||||
$className=substr(basename($command),0,-4);
|
||||
if(!class_exists($className,false))
|
||||
require_once($command);
|
||||
}
|
||||
else // an alias
|
||||
$className=Yii::import($command);
|
||||
return new $className($name,$this);
|
||||
}
|
||||
else // an array configuration
|
||||
return Yii::createComponent($command,$name,$this);
|
||||
}
|
||||
elseif($name==='help')
|
||||
return new CHelpCommand('help',$this);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* CConsoleCommandRunner class file.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright 2008-2013 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
/**
|
||||
* CConsoleCommandRunner manages commands and executes the requested command.
|
||||
*
|
||||
* @property string $scriptName The entry script name.
|
||||
* @property CConsoleCommand $command The currently active command.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @package system.console
|
||||
* @since 1.0
|
||||
*/
|
||||
class CConsoleCommandRunner extends CComponent
|
||||
{
|
||||
/**
|
||||
* @var array list of all available commands (command name=>command configuration).
|
||||
* Each command configuration can be either a string or an array.
|
||||
* If the former, the string should be the class name or
|
||||
* {@link YiiBase::getPathOfAlias class path alias} of the command.
|
||||
* If the latter, the array must contain a 'class' element which specifies
|
||||
* the command's class name or {@link YiiBase::getPathOfAlias class path alias}.
|
||||
* The rest name-value pairs in the array are used to initialize
|
||||
* the corresponding command properties. For example,
|
||||
* <pre>
|
||||
* array(
|
||||
* 'email'=>array(
|
||||
* 'class'=>'path.to.Mailer',
|
||||
* 'interval'=>3600,
|
||||
* ),
|
||||
* 'log'=>'path.to.LoggerCommand',
|
||||
* )
|
||||
* </pre>
|
||||
*/
|
||||
public $commands=array();
|
||||
|
||||
private $_scriptName;
|
||||
private $_command;
|
||||
|
||||
/**
|
||||
* Executes the requested command.
|
||||
* @param array $args list of user supplied parameters (including the entry script name and the command name).
|
||||
* @return integer|null application exit code returned by the command.
|
||||
* if null is returned, application will not exit explicitly. See also {@link CConsoleApplication::processRequest()}.
|
||||
* (return value is available since version 1.1.11)
|
||||
*/
|
||||
public function run($args)
|
||||
{
|
||||
$this->_scriptName=$args[0];
|
||||
array_shift($args);
|
||||
if(isset($args[0]))
|
||||
{
|
||||
$name=$args[0];
|
||||
array_shift($args);
|
||||
}
|
||||
else
|
||||
$name='help';
|
||||
|
||||
$oldCommand=$this->_command;
|
||||
if(($command=$this->createCommand($name))===null)
|
||||
$command=$this->createCommand('help');
|
||||
$this->_command=$command;
|
||||
$command->init();
|
||||
$exitCode=$command->run($args);
|
||||
$this->_command=$oldCommand;
|
||||
return $exitCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the entry script name
|
||||
*/
|
||||
public function getScriptName()
|
||||
{
|
||||
return $this->_scriptName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently running command.
|
||||
* @return CConsoleCommand|null the currently active command.
|
||||
* @since 1.1.14
|
||||
*/
|
||||
public function getCommand()
|
||||
{
|
||||
return $this->_command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CConsoleCommand $value the currently active command.
|
||||
* @since 1.1.14
|
||||
*/
|
||||
public function setCommand($value)
|
||||
{
|
||||
$this->_command=$value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for commands under the specified directory.
|
||||
* @param string $path the directory containing the command class files.
|
||||
* @return array list of commands (command name=>command class file)
|
||||
*/
|
||||
public function findCommands($path)
|
||||
{
|
||||
if(($dir=@opendir($path))===false)
|
||||
return array();
|
||||
$commands=array();
|
||||
while(($name=readdir($dir))!==false)
|
||||
{
|
||||
$file=$path.DIRECTORY_SEPARATOR.$name;
|
||||
if(!strcasecmp(substr($name,-11),'Command.php') && is_file($file))
|
||||
$commands[strtolower(substr($name,0,-11))]=$file;
|
||||
}
|
||||
closedir($dir);
|
||||
return $commands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds commands from the specified command path.
|
||||
* If a command already exists, the new one will be ignored.
|
||||
* @param string $path the alias of the directory containing the command class files.
|
||||
*/
|
||||
public function addCommands($path)
|
||||
{
|
||||
if(($commands=$this->findCommands($path))!==array())
|
||||
{
|
||||
foreach($commands as $name=>$file)
|
||||
{
|
||||
if(!isset($this->commands[$name]))
|
||||
$this->commands[$name]=$file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name command name (case-insensitive)
|
||||
* @return CConsoleCommand the command object. Null if the name is invalid.
|
||||
*/
|
||||
public function createCommand($name)
|
||||
{
|
||||
$name=strtolower($name);
|
||||
|
||||
$command=null;
|
||||
if(isset($this->commands[$name]))
|
||||
$command=$this->commands[$name];
|
||||
else
|
||||
{
|
||||
$commands=array_change_key_case($this->commands);
|
||||
if(isset($commands[$name]))
|
||||
$command=$commands[$name];
|
||||
}
|
||||
|
||||
if($command!==null)
|
||||
{
|
||||
if(is_string($command)) // class file path or alias
|
||||
{
|
||||
if(strpos($command,'/')!==false || strpos($command,'\\')!==false)
|
||||
{
|
||||
$className=substr(basename($command),0,-4);
|
||||
if(!class_exists($className,false))
|
||||
require_once($command);
|
||||
}
|
||||
else // an alias
|
||||
$className=Yii::import($command);
|
||||
return new $className($name,$this);
|
||||
}
|
||||
else // an array configuration
|
||||
return Yii::createComponent($command,$name,$this);
|
||||
}
|
||||
elseif($name==='help')
|
||||
return new CHelpCommand('help',$this);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,76 +1,76 @@
|
|||
<?php
|
||||
/**
|
||||
* CHelpCommand class file.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright 2008-2013 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
/**
|
||||
* CHelpCommand represents a console help command.
|
||||
*
|
||||
* CHelpCommand displays the available command list or the help instructions
|
||||
* about a specific command.
|
||||
*
|
||||
* To use this command, enter the following on the command line:
|
||||
* <pre>
|
||||
* php path/to/entry_script.php help [command name]
|
||||
* </pre>
|
||||
* In the above, if the command name is not provided, it will display all
|
||||
* available commands.
|
||||
*
|
||||
* @property string $help The command description.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @package system.console
|
||||
* @since 1.0
|
||||
*/
|
||||
class CHelpCommand extends CConsoleCommand
|
||||
{
|
||||
/**
|
||||
* Execute the action.
|
||||
* @param array $args command line parameters specific for this command
|
||||
* @return integer non zero application exit code after printing help
|
||||
*/
|
||||
public function run($args)
|
||||
{
|
||||
$runner=$this->getCommandRunner();
|
||||
$commands=$runner->commands;
|
||||
if(isset($args[0]))
|
||||
$name=strtolower($args[0]);
|
||||
if(!isset($args[0]) || !isset($commands[$name]))
|
||||
{
|
||||
if(!empty($commands))
|
||||
{
|
||||
echo "Yii command runner (based on Yii v".Yii::getVersion().")\n";
|
||||
echo "Usage: ".$runner->getScriptName()." <command-name> [parameters...]\n";
|
||||
echo "\nThe following commands are available:\n";
|
||||
$commandNames=array_keys($commands);
|
||||
sort($commandNames);
|
||||
echo ' - '.implode("\n - ",$commandNames);
|
||||
echo "\n\nTo see individual command help, use the following:\n";
|
||||
echo " ".$runner->getScriptName()." help <command-name>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "No available commands.\n";
|
||||
echo "Please define them under the following directory:\n";
|
||||
echo "\t".Yii::app()->getCommandPath()."\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
echo $runner->createCommand($name)->getHelp();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the command description.
|
||||
* @return string the command description.
|
||||
*/
|
||||
public function getHelp()
|
||||
{
|
||||
return parent::getHelp().' [command-name]';
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* CHelpCommand class file.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright 2008-2013 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
/**
|
||||
* CHelpCommand represents a console help command.
|
||||
*
|
||||
* CHelpCommand displays the available command list or the help instructions
|
||||
* about a specific command.
|
||||
*
|
||||
* To use this command, enter the following on the command line:
|
||||
* <pre>
|
||||
* php path/to/entry_script.php help [command name]
|
||||
* </pre>
|
||||
* In the above, if the command name is not provided, it will display all
|
||||
* available commands.
|
||||
*
|
||||
* @property string $help The command description.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @package system.console
|
||||
* @since 1.0
|
||||
*/
|
||||
class CHelpCommand extends CConsoleCommand
|
||||
{
|
||||
/**
|
||||
* Execute the action.
|
||||
* @param array $args command line parameters specific for this command
|
||||
* @return integer non zero application exit code after printing help
|
||||
*/
|
||||
public function run($args)
|
||||
{
|
||||
$runner=$this->getCommandRunner();
|
||||
$commands=$runner->commands;
|
||||
if(isset($args[0]))
|
||||
$name=strtolower($args[0]);
|
||||
if(!isset($args[0]) || !isset($commands[$name]))
|
||||
{
|
||||
if(!empty($commands))
|
||||
{
|
||||
echo "Yii command runner (based on Yii v".Yii::getVersion().")\n";
|
||||
echo "Usage: ".$runner->getScriptName()." <command-name> [parameters...]\n";
|
||||
echo "\nThe following commands are available:\n";
|
||||
$commandNames=array_keys($commands);
|
||||
sort($commandNames);
|
||||
echo ' - '.implode("\n - ",$commandNames);
|
||||
echo "\n\nTo see individual command help, use the following:\n";
|
||||
echo " ".$runner->getScriptName()." help <command-name>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "No available commands.\n";
|
||||
echo "Please define them under the following directory:\n";
|
||||
echo "\t".Yii::app()->getCommandPath()."\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
echo $runner->createCommand($name)->getHelp();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the command description.
|
||||
* @return string the command description.
|
||||
*/
|
||||
public function getHelp()
|
||||
{
|
||||
return parent::getHelp().' [command-name]';
|
||||
}
|
||||
}
|
|
@ -295,7 +295,7 @@ class CDbConnection extends CApplicationComponent
|
|||
|
||||
if($this->emulatePrepare && constant('PDO::ATTR_EMULATE_PREPARES'))
|
||||
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,true);
|
||||
|
||||
|
||||
if($this->charset!==null)
|
||||
{
|
||||
if(strcasecmp($pdo->getAttribute(PDO::ATTR_DRIVER_NAME),'sqlite'))
|
||||
|
|
|
@ -189,8 +189,8 @@ class CDateFormatter extends CComponent
|
|||
|
||||
/**
|
||||
* Get the year.
|
||||
* "yy" will return the last two digits of year.
|
||||
* "y...y" will pad the year with 0 in the front, e.g. "yyyyy" will generate "02008" for year 2008.
|
||||
* "yy" will return the last two digits of year.
|
||||
* "y...y" will pad the year with 0 in the front, e.g. "yyyyy" will generate "02008" for year 2008.
|
||||
* @param string a pattern.
|
||||
* @param array result of {@link CTimestamp::getdate}.
|
||||
* @return string formatted year
|
||||
|
@ -206,11 +206,11 @@ class CDateFormatter extends CComponent
|
|||
|
||||
/**
|
||||
* Get the month.
|
||||
* "M" will return integer 1 through 12;
|
||||
* "MM" will return two digits month number with necessary zero padding, e.g. 05;
|
||||
* "MMM" will return the abrreviated month name, e.g. "Jan";
|
||||
* "MMMM" will return the full month name, e.g. "January";
|
||||
* "MMMMM" will return the narrow month name, e.g. "J";
|
||||
* "M" will return integer 1 through 12;
|
||||
* "MM" will return two digits month number with necessary zero padding, e.g. 05;
|
||||
* "MMM" will return the abrreviated month name, e.g. "Jan";
|
||||
* "MMMM" will return the full month name, e.g. "January";
|
||||
* "MMMMM" will return the narrow month name, e.g. "J";
|
||||
* @param string a pattern.
|
||||
* @param array result of {@link CTimestamp::getdate}.
|
||||
* @return string month name
|
||||
|
@ -237,7 +237,7 @@ class CDateFormatter extends CComponent
|
|||
|
||||
/**
|
||||
* Get the day of the month.
|
||||
* "d" for non-padding, "dd" will always return 2 digits day numbers, e.g. 05.
|
||||
* "d" for non-padding, "dd" will always return 2 digits day numbers, e.g. 05.
|
||||
* @param string a pattern.
|
||||
* @param array result of {@link CTimestamp::getdate}.
|
||||
* @return string day of the month
|
||||
|
@ -284,9 +284,9 @@ class CDateFormatter extends CComponent
|
|||
|
||||
/**
|
||||
* Get the day of the week.
|
||||
* "E", "EE", "EEE" will return abbreviated week day name, e.g. "Tues";
|
||||
* "EEEE" will return full week day name;
|
||||
* "EEEEE" will return the narrow week day name, e.g. "T";
|
||||
* "E", "EE", "EEE" will return abbreviated week day name, e.g. "Tues";
|
||||
* "EEEE" will return full week day name;
|
||||
* "EEEEE" will return the narrow week day name, e.g. "T";
|
||||
* @param string a pattern.
|
||||
* @param array result of {@link CTimestamp::getdate}.
|
||||
* @return string day of the week.
|
||||
|
|
|
@ -115,7 +115,7 @@ return array (
|
|||
'The column "{column}" is not a foreign key in table "{table}".' => 'La colonne "{column}" n\'est pas une clef étrangère de la table "{table}".',
|
||||
'The command path "{path}" is not a valid directory.' => 'Le chemin d\'accès à la ligne de commande "{path}" n\'est pas un dossier valide.',
|
||||
'The controller path "{path}" is not a valid directory.' => 'Le chemin d\'accès au contrôleur "{path}" n\'est pas un dossier valide.',
|
||||
'The file "{file}" cannot be uploaded. Only files with these extensions are allowed: {extensions}.' =>
|
||||
'The file "{file}" cannot be uploaded. Only files with these extensions are allowed: {extensions}.' =>
|
||||
'Le fichier "{file}" ne peut être téléchargé. Les extensions de fichier autorisées sont: {extensions}.',
|
||||
'The file "{file}" is too large. Its size cannot exceed {limit} bytes.' => 'Le fichier "{file}" est trop gros. Sa taille ne peut être supérieure à {limit} octets.',
|
||||
'The file "{file}" is too small. Its size cannot be smaller than {limit} bytes.' => 'Le fichier "{file}" est trop petit. Sa taille ne peut être inférieure à {limit} octets.',
|
||||
|
@ -160,7 +160,7 @@ return array (
|
|||
'This content requires the <a href="http://www.adobe.com/go/getflash/">Adobe Flash Player</a>.' => 'Ce contenu nécessite le <a href="http://www.adobe.com/go/getflash/">Lecteur Flash d\'Adobe</a>.',
|
||||
'Unable to add an item whose name is the same as an existing item.' => 'Impossible d\'ajouter un élément dont le nom est identique à celui d\'un autre éléménet.',
|
||||
'Unable to change the item name. The name "{name}" is already used by another item.' => 'Impossible de changer le nom de l\'élément. Le nom "{name}" est déjà affecté à un autre élémnent.',
|
||||
'Unable to create application state file "{file}". Make sure the directory containing the file exists and is writable by the Web server process.' =>
|
||||
'Unable to create application state file "{file}". Make sure the directory containing the file exists and is writable by the Web server process.' =>
|
||||
'Impossible de créer le fichier "{file}" de gestion d\'état de l\'application. Vérifiez que le fichier existe et que le proccessus du serveur web peut y accéder en écriture.',
|
||||
'Unable to find the decorator view "{view}".' => 'Impossible de trouver la vue décorateur "{view}".',
|
||||
'Unable to find the list item.' => 'Impossible de trouver l\'élément de la liste.',
|
||||
|
|
|
@ -143,7 +143,7 @@ return array (
|
|||
'The pattern for week in year must be "w".' => 'Шаблон за седмицу у години мора бити "w".',
|
||||
'The queue is empty.' => 'Ред (queue) је празан.',
|
||||
'The relation "{relation}" in active record class "{class}" is not specified correctly: the join table "{joinTable}" given in the foreign key cannot be found in the database.' => 'Релација "{relation}" у active record класи "{class}" није специфицирана исправно: придружена табела (join table) "{joinTable}" задата у спољном кључу (foreign key) не може бити пронађена у бази.',
|
||||
'The relation "{relation}" in active record class "{class}" is specified with an incomplete foreign key. The foreign key must consist of columns referencing both joining tables.' => 'Релација "{relation}" у active record класи "{class}" је специфицирана са некомплетним спољним кључем (foreign key). Спољни кључ (foreign key) мора се састојати од колона које референцирају обе табеле за спајање (joining tables).',
|
||||
'The relation "{relation}" in active record class "{class}" is specified with an incomplete foreign key. The foreign key must consist of columns referencing both joining tables.' => 'Релација "{relation}" у active record класи "{class}" је специфицирана са некомплетним спољним кључем (foreign key). Спољни кључ (foreign key) мора се састојати од колона које референцирају обе табеле за спајање (joining tables).',
|
||||
'The relation "{relation}" in active record class "{class}" is specified with an invalid foreign key "{key}". The foreign key does not point to either joining table.' => 'Релација "{relation}" u active record класи "{class}" је специфицирана погрешним спољним кључем (foreign key) "{key}". Спољни кључ (foreign key) не показује ни на једну табелу за спајање (joining tables).',
|
||||
'The relation "{relation}" in active record class "{class}" is specified with an invalid foreign key. The format of the foreign key must be "joinTable(fk1,fk2,...)".' => 'Релација "{relation}" u active record класи "{class}" је специфицирана погрешним спољним кључем (foreign key). Формат спољног кључа (foreign key) мора бити "joinTable(fk1,fk2,...)',
|
||||
'The requested controller "{controller}" does not exist.' => 'Захтевани контролер "{controller}" не постоји.',
|
||||
|
|
|
@ -34,7 +34,7 @@ class CFileHelper
|
|||
* Level -1 means copying all directories and files under the directory;
|
||||
* Level 0 means copying only the files DIRECTLY under the directory;
|
||||
* level N means copying those directories that are within N levels.
|
||||
* </li>
|
||||
* </li>
|
||||
* </ul>
|
||||
*/
|
||||
public static function copyDirectory($src,$dst,$options=array())
|
||||
|
@ -60,7 +60,7 @@ class CFileHelper
|
|||
* Level -1 means searching for all directories and files under the directory;
|
||||
* Level 0 means searching for only the files DIRECTLY under the directory;
|
||||
* level N means searching for those directories that are within N levels.
|
||||
* </li>
|
||||
* </li>
|
||||
* </ul>
|
||||
* @return array files found under the directory. The file list is sorted.
|
||||
*/
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
<!DOCTYPE html PUBLIC
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>Erreur <?php echo $data['code']; ?></title>
|
||||
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
|
||||
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
|
||||
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
|
||||
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
|
||||
p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
|
||||
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
|
||||
/*]]>*/
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Erreur <?php echo $data['code']; ?></h1>
|
||||
<h2><?php echo nl2br(CHtml::encode($data['message'])); ?></h2>
|
||||
<p>
|
||||
L'erreur ci-dessus est apparue pendant que le serveur Web traitait votre requête.
|
||||
</p>
|
||||
<p>
|
||||
Si vous pensez qu'il s'agit d'une erreur du serveur, veuillez contacter <?php echo $data['admin']; ?>.
|
||||
</p>
|
||||
<p>
|
||||
Merci.
|
||||
</p>
|
||||
<div class="version">
|
||||
<?php echo date('Y-m-d H:i:s',$data['time']) .' '. $data['version']; ?>
|
||||
</div>
|
||||
</body>
|
||||
<!DOCTYPE html PUBLIC
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>Erreur <?php echo $data['code']; ?></title>
|
||||
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
|
||||
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
|
||||
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
|
||||
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
|
||||
p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
|
||||
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
|
||||
/*]]>*/
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Erreur <?php echo $data['code']; ?></h1>
|
||||
<h2><?php echo nl2br(CHtml::encode($data['message'])); ?></h2>
|
||||
<p>
|
||||
L'erreur ci-dessus est apparue pendant que le serveur Web traitait votre requête.
|
||||
</p>
|
||||
<p>
|
||||
Si vous pensez qu'il s'agit d'une erreur du serveur, veuillez contacter <?php echo $data['admin']; ?>.
|
||||
</p>
|
||||
<p>
|
||||
Merci.
|
||||
</p>
|
||||
<div class="version">
|
||||
<?php echo date('Y-m-d H:i:s',$data['time']) .' '. $data['version']; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,33 +1,33 @@
|
|||
<!DOCTYPE html PUBLIC
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>Demande incorrecte</title>
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
|
||||
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
|
||||
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
|
||||
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
|
||||
p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
|
||||
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
|
||||
/*]]>*/
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Demande Incorrecte</h1>
|
||||
<h2><?php echo nl2br(CHtml::encode($data['message'])); ?></h2>
|
||||
<p>
|
||||
La demande n'a pas pu être interprétée par le serveur, due à une mauvaise syntaxe.
|
||||
Merci de ne pas répeter la requete sans modifications.
|
||||
</p>
|
||||
<p>
|
||||
Si vous pensez qu'il s'agit d'une erreur du serveur, veuillez contacter <?php echo $data['admin']; ?>.
|
||||
</p>
|
||||
<div class="version">
|
||||
<?php echo date('Y-m-d H:i:s',$data['time']) .' '. $data['version']; ?>
|
||||
</div>
|
||||
</body>
|
||||
<!DOCTYPE html PUBLIC
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>Demande incorrecte</title>
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
|
||||
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
|
||||
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
|
||||
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
|
||||
p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
|
||||
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
|
||||
/*]]>*/
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Demande Incorrecte</h1>
|
||||
<h2><?php echo nl2br(CHtml::encode($data['message'])); ?></h2>
|
||||
<p>
|
||||
La demande n'a pas pu être interprétée par le serveur, due à une mauvaise syntaxe.
|
||||
Merci de ne pas répeter la requete sans modifications.
|
||||
</p>
|
||||
<p>
|
||||
Si vous pensez qu'il s'agit d'une erreur du serveur, veuillez contacter <?php echo $data['admin']; ?>.
|
||||
</p>
|
||||
<div class="version">
|
||||
<?php echo date('Y-m-d H:i:s',$data['time']) .' '. $data['version']; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,32 +1,32 @@
|
|||
<!DOCTYPE html PUBLIC
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>Accès interdit</title>
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
|
||||
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
|
||||
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
|
||||
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
|
||||
p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
|
||||
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
|
||||
/*]]>*/
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Accès interdit</h1>
|
||||
<h2><?php echo nl2br(CHtml::encode($data['message'])); ?></h2>
|
||||
<p>
|
||||
Vous n'avez pas les autorisations nécessaires pour accéder à cette page.
|
||||
</p>
|
||||
<p>
|
||||
Si vous pensez qu'il s'agit d'une erreur du serveur, veuillez contacter <?php echo $data['admin']; ?>.
|
||||
</p>
|
||||
<div class="version">
|
||||
<?php echo date('Y-m-d H:i:s',$data['time']) .' '. $data['version']; ?>
|
||||
</div>
|
||||
</body>
|
||||
<!DOCTYPE html PUBLIC
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>Accès interdit</title>
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
|
||||
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
|
||||
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
|
||||
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
|
||||
p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
|
||||
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
|
||||
/*]]>*/
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Accès interdit</h1>
|
||||
<h2><?php echo nl2br(CHtml::encode($data['message'])); ?></h2>
|
||||
<p>
|
||||
Vous n'avez pas les autorisations nécessaires pour accéder à cette page.
|
||||
</p>
|
||||
<p>
|
||||
Si vous pensez qu'il s'agit d'une erreur du serveur, veuillez contacter <?php echo $data['admin']; ?>.
|
||||
</p>
|
||||
<div class="version">
|
||||
<?php echo date('Y-m-d H:i:s',$data['time']) .' '. $data['version']; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,34 +1,34 @@
|
|||
<!DOCTYPE html PUBLIC
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>Page Non trouvée</title>
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
|
||||
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
|
||||
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
|
||||
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
|
||||
p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
|
||||
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
|
||||
/*]]>*/
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Page Non trouvée</h1>
|
||||
<h2><?php echo nl2br(CHtml::encode($data['message'])); ?></h2>
|
||||
<p>
|
||||
L'URL demandée n'existe pas sur ce serveur.
|
||||
If you entered the URL manually please check your spelling and try again.
|
||||
Si vous avez saisi l'URL manuellement, vérifiez la, et réessayez.
|
||||
</p>
|
||||
<p>
|
||||
Si vous pensez qu'il s'agit d'une erreur du serveur, veuillez contacter <?php echo $data['admin']; ?>.
|
||||
</p>
|
||||
<div class="version">
|
||||
<?php echo date('Y-m-d H:i:s',$data['time']) .' '. $data['version']; ?>
|
||||
</div>
|
||||
</body>
|
||||
<!DOCTYPE html PUBLIC
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>Page Non trouvée</title>
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
|
||||
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
|
||||
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
|
||||
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
|
||||
p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
|
||||
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
|
||||
/*]]>*/
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Page Non trouvée</h1>
|
||||
<h2><?php echo nl2br(CHtml::encode($data['message'])); ?></h2>
|
||||
<p>
|
||||
L'URL demandée n'existe pas sur ce serveur.
|
||||
If you entered the URL manually please check your spelling and try again.
|
||||
Si vous avez saisi l'URL manuellement, vérifiez la, et réessayez.
|
||||
</p>
|
||||
<p>
|
||||
Si vous pensez qu'il s'agit d'une erreur du serveur, veuillez contacter <?php echo $data['admin']; ?>.
|
||||
</p>
|
||||
<div class="version">
|
||||
<?php echo date('Y-m-d H:i:s',$data['time']) .' '. $data['version']; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,35 +1,35 @@
|
|||
<!DOCTYPE html PUBLIC
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>Erreur interne du serveur</title>
|
||||
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
|
||||
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
|
||||
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
|
||||
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
|
||||
p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
|
||||
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
|
||||
/*]]>*/
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Erreur interne du serveur</h1>
|
||||
<h2><?php echo nl2br(CHtml::encode($data['message'])); ?></h2>
|
||||
<p>
|
||||
Une erreur interne est apparue lorsque le serveur web traitait votre requete.
|
||||
Veuillez contacter <?php echo $data['admin']; ?> pour signaler ce problème.
|
||||
</p>
|
||||
<p>
|
||||
Merci.
|
||||
</p>
|
||||
<div class="version">
|
||||
<?php echo date('Y-m-d H:i:s',$data['time']) .' '. $data['version']; ?>
|
||||
</div>
|
||||
</body>
|
||||
<!DOCTYPE html PUBLIC
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>Erreur interne du serveur</title>
|
||||
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
|
||||
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
|
||||
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
|
||||
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
|
||||
p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
|
||||
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
|
||||
/*]]>*/
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Erreur interne du serveur</h1>
|
||||
<h2><?php echo nl2br(CHtml::encode($data['message'])); ?></h2>
|
||||
<p>
|
||||
Une erreur interne est apparue lorsque le serveur web traitait votre requete.
|
||||
Veuillez contacter <?php echo $data['admin']; ?> pour signaler ce problème.
|
||||
</p>
|
||||
<p>
|
||||
Merci.
|
||||
</p>
|
||||
<div class="version">
|
||||
<?php echo date('Y-m-d H:i:s',$data['time']) .' '. $data['version']; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,31 +1,31 @@
|
|||
<!DOCTYPE html PUBLIC
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>Service non disponible</title>
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
|
||||
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
|
||||
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
|
||||
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
|
||||
p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
|
||||
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
|
||||
/*]]>*/
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Service non disponible</h1>
|
||||
<p>
|
||||
Notre système est momentanément indisponible. Merci de réessayer plus tard.
|
||||
</p>
|
||||
<p>
|
||||
Merci.
|
||||
</p>
|
||||
<div class="version">
|
||||
<?php echo date('Y-m-d H:i:s',$data['time']) .' '. $data['version']; ?>
|
||||
</div>
|
||||
</body>
|
||||
<!DOCTYPE html PUBLIC
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>Service non disponible</title>
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
|
||||
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
|
||||
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
|
||||
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
|
||||
p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
|
||||
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
|
||||
/*]]>*/
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Service non disponible</h1>
|
||||
<p>
|
||||
Notre système est momentanément indisponible. Merci de réessayer plus tard.
|
||||
</p>
|
||||
<p>
|
||||
Merci.
|
||||
</p>
|
||||
<div class="version">
|
||||
<?php echo date('Y-m-d H:i:s',$data['time']) .' '. $data['version']; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,74 +1,74 @@
|
|||
<!DOCTYPE html PUBLIC
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>
|
||||
<?php echo CHtml::encode($data['type']); ?>
|
||||
</title>
|
||||
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
|
||||
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
|
||||
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
|
||||
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
|
||||
p {font-family:"Verdana";font-size:9pt;}
|
||||
pre {font-family:"Lucida Console";font-size:10pt;}
|
||||
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
|
||||
.message {color: maroon;}
|
||||
.source {font-family:"Lucida Console";font-weight:normal;background-color:#ffffee;}
|
||||
.error {background-color: #ffeeee;}
|
||||
/*]]>*/
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1><?php echo $data['type']; ?></h1>
|
||||
|
||||
<h3>Description</h3>
|
||||
<p class="message">
|
||||
<?php echo nl2br(CHtml::encode($data['message'])); ?>
|
||||
</p>
|
||||
|
||||
<h3>Fichier Source</h3>
|
||||
<p>
|
||||
<?php echo CHtml::encode($data['file'])."({$data['line']})"; ?>
|
||||
</p>
|
||||
|
||||
<div class="source">
|
||||
<pre>
|
||||
<?php
|
||||
if(empty($data['source']))
|
||||
echo 'Aucun code source disponible.';
|
||||
else
|
||||
{
|
||||
foreach($data['source'] as $line=>$code)
|
||||
{
|
||||
if($line!==$data['line'])
|
||||
echo CHtml::encode(sprintf("%05d: %s",$line,str_replace("\t",' ',$code)));
|
||||
else
|
||||
{
|
||||
echo "<div class=\"error\">";
|
||||
echo CHtml::encode(sprintf("%05d: %s",$line,str_replace("\t",' ',$code)));
|
||||
echo "</div>";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</pre>
|
||||
</div><!-- end of source -->
|
||||
|
||||
<h3>Pile d'exécution</h3>
|
||||
<div class="callstack">
|
||||
<pre>
|
||||
<?php echo CHtml::encode($data['trace']); ?>
|
||||
</pre>
|
||||
</div><!-- end of callstack -->
|
||||
|
||||
<div class="version">
|
||||
<?php echo date('Y-m-d H:i:s',$data['time']) .' '. $data['version']; ?>
|
||||
</div>
|
||||
</body>
|
||||
<!DOCTYPE html PUBLIC
|
||||
"-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<title>
|
||||
<?php echo CHtml::encode($data['type']); ?>
|
||||
</title>
|
||||
|
||||
<style type="text/css">
|
||||
/*<![CDATA[*/
|
||||
body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
|
||||
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
|
||||
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
|
||||
h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
|
||||
p {font-family:"Verdana";font-size:9pt;}
|
||||
pre {font-family:"Lucida Console";font-size:10pt;}
|
||||
.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
|
||||
.message {color: maroon;}
|
||||
.source {font-family:"Lucida Console";font-weight:normal;background-color:#ffffee;}
|
||||
.error {background-color: #ffeeee;}
|
||||
/*]]>*/
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1><?php echo $data['type']; ?></h1>
|
||||
|
||||
<h3>Description</h3>
|
||||
<p class="message">
|
||||
<?php echo nl2br(CHtml::encode($data['message'])); ?>
|
||||
</p>
|
||||
|
||||
<h3>Fichier Source</h3>
|
||||
<p>
|
||||
<?php echo CHtml::encode($data['file'])."({$data['line']})"; ?>
|
||||
</p>
|
||||
|
||||
<div class="source">
|
||||
<pre>
|
||||
<?php
|
||||
if(empty($data['source']))
|
||||
echo 'Aucun code source disponible.';
|
||||
else
|
||||
{
|
||||
foreach($data['source'] as $line=>$code)
|
||||
{
|
||||
if($line!==$data['line'])
|
||||
echo CHtml::encode(sprintf("%05d: %s",$line,str_replace("\t",' ',$code)));
|
||||
else
|
||||
{
|
||||
echo "<div class=\"error\">";
|
||||
echo CHtml::encode(sprintf("%05d: %s",$line,str_replace("\t",' ',$code)));
|
||||
echo "</div>";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</pre>
|
||||
</div><!-- end of source -->
|
||||
|
||||
<h3>Pile d'exécution</h3>
|
||||
<div class="callstack">
|
||||
<pre>
|
||||
<?php echo CHtml::encode($data['trace']); ?>
|
||||
</pre>
|
||||
</div><!-- end of callstack -->
|
||||
|
||||
<div class="version">
|
||||
<?php echo date('Y-m-d H:i:s',$data['time']) .' '. $data['version']; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,23 +1,23 @@
|
|||
<script language="javascript" type="text/javascript">
|
||||
/*<![CDATA[*/
|
||||
if(typeof(console)=='object')
|
||||
{
|
||||
console.group("Application Log");
|
||||
<?php
|
||||
foreach($data as $index=>$log)
|
||||
{
|
||||
$time=date('H:i:s.',$log[3]).(int)(($log[3]-(int)$log[3])*1000);
|
||||
if($log[1]===CLogger::LEVEL_WARNING)
|
||||
$func='warn';
|
||||
else if($log[1]===CLogger::LEVEL_ERROR)
|
||||
$func='error';
|
||||
else
|
||||
$func='log';
|
||||
$content=CJavaScript::quote("[$time][$log[1]][$log[2]] $log[0]");
|
||||
echo "\tconsole.{$func}(\"{$content}\");\n";
|
||||
}
|
||||
?>
|
||||
console.groupEnd();
|
||||
}
|
||||
/*]]>*/
|
||||
<script language="javascript" type="text/javascript">
|
||||
/*<![CDATA[*/
|
||||
if(typeof(console)=='object')
|
||||
{
|
||||
console.group("Application Log");
|
||||
<?php
|
||||
foreach($data as $index=>$log)
|
||||
{
|
||||
$time=date('H:i:s.',$log[3]).(int)(($log[3]-(int)$log[3])*1000);
|
||||
if($log[1]===CLogger::LEVEL_WARNING)
|
||||
$func='warn';
|
||||
else if($log[1]===CLogger::LEVEL_ERROR)
|
||||
$func='error';
|
||||
else
|
||||
$func='log';
|
||||
$content=CJavaScript::quote("[$time][$log[1]][$log[2]] $log[0]");
|
||||
echo "\tconsole.{$func}(\"{$content}\");\n";
|
||||
}
|
||||
?>
|
||||
console.groupEnd();
|
||||
}
|
||||
/*]]>*/
|
||||
</script>
|
|
@ -1,32 +1,32 @@
|
|||
<!-- start log messages -->
|
||||
<table width="100%" cellpadding="2" style="border-spacing:1px;font:11px Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;color:#666666;">
|
||||
<tr>
|
||||
<th style="background:black;color:white;" colspan="5">
|
||||
Journal d'application
|
||||
</th>
|
||||
</tr>
|
||||
<tr style="background-color: #ccc;">
|
||||
<th style="width:120px">Heure</th>
|
||||
<th>Niveau</th>
|
||||
<th>Categorie</th>
|
||||
<th>Message</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach($data as $index=>$log)
|
||||
{
|
||||
$color=($index%2)?'#F5F5F5':'#EBF8FE';
|
||||
$message=CHtml::encode($log[0]);
|
||||
$time=date('H:i:s.',$log[3]).(int)(($log[3]-(int)$log[3])*1000000);
|
||||
|
||||
echo <<<EOD
|
||||
<tr style="background:{$color}">
|
||||
<td align="center">{$time}</td>
|
||||
<td>{$log[1]}</td>
|
||||
<td>{$log[2]}</td>
|
||||
<td>{$message}</td>
|
||||
</tr>
|
||||
EOD;
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<!-- start log messages -->
|
||||
<table width="100%" cellpadding="2" style="border-spacing:1px;font:11px Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;color:#666666;">
|
||||
<tr>
|
||||
<th style="background:black;color:white;" colspan="5">
|
||||
Journal d'application
|
||||
</th>
|
||||
</tr>
|
||||
<tr style="background-color: #ccc;">
|
||||
<th style="width:120px">Heure</th>
|
||||
<th>Niveau</th>
|
||||
<th>Categorie</th>
|
||||
<th>Message</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach($data as $index=>$log)
|
||||
{
|
||||
$color=($index%2)?'#F5F5F5':'#EBF8FE';
|
||||
$message=CHtml::encode($log[0]);
|
||||
$time=date('H:i:s.',$log[3]).(int)(($log[3]-(int)$log[3])*1000000);
|
||||
|
||||
echo <<<EOD
|
||||
<tr style="background:{$color}">
|
||||
<td align="center">{$time}</td>
|
||||
<td>{$log[1]}</td>
|
||||
<td>{$log[2]}</td>
|
||||
<td>{$message}</td>
|
||||
</tr>
|
||||
EOD;
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<!-- end of log messages -->
|
|
@ -1,19 +1,19 @@
|
|||
<script language="javascript" type="text/javascript">
|
||||
/*<![CDATA[*/
|
||||
if(typeof(console)=='object')
|
||||
{
|
||||
console.group("Profiling Callstack Report");
|
||||
<?php
|
||||
foreach($data as $index=>$entry)
|
||||
{
|
||||
list($proc,$time,$level)=$entry;
|
||||
$proc=CJavaScript::quote($proc);
|
||||
$time=sprintf('%0.5f',$time);
|
||||
$spaces=str_repeat(' ',$level*8);
|
||||
echo "\tconsole.log(\"[$time]{$spaces}{$proc}\");\n";
|
||||
}
|
||||
?>
|
||||
console.groupEnd();
|
||||
}
|
||||
/*]]>*/
|
||||
<script language="javascript" type="text/javascript">
|
||||
/*<![CDATA[*/
|
||||
if(typeof(console)=='object')
|
||||
{
|
||||
console.group("Profiling Callstack Report");
|
||||
<?php
|
||||
foreach($data as $index=>$entry)
|
||||
{
|
||||
list($proc,$time,$level)=$entry;
|
||||
$proc=CJavaScript::quote($proc);
|
||||
$time=sprintf('%0.5f',$time);
|
||||
$spaces=str_repeat(' ',$level*8);
|
||||
echo "\tconsole.log(\"[$time]{$spaces}{$proc}\");\n";
|
||||
}
|
||||
?>
|
||||
console.groupEnd();
|
||||
}
|
||||
/*]]>*/
|
||||
</script>
|
|
@ -1,30 +1,30 @@
|
|||
<!-- start profiling callstack -->
|
||||
<table width="100%" cellpadding="2" style="border-spacing:1px;font:11px Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;color:#666666;">
|
||||
<tr>
|
||||
<th style="background:black;color:white;" colspan="2">
|
||||
Profiling Callstack Report
|
||||
</th>
|
||||
</tr>
|
||||
<tr style="background-color: #ccc;">
|
||||
<th>Procedure</th>
|
||||
<th>Time (s)</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach($data as $index=>$entry)
|
||||
{
|
||||
$color=($index%2)?'#F5F5F5':'#EBF8FE';
|
||||
list($proc,$time,$level)=$entry;
|
||||
$proc=CHtml::encode($proc);
|
||||
$time=sprintf('%0.5f',$time);
|
||||
$spaces=str_repeat(' ',$level*8);
|
||||
|
||||
echo <<<EOD
|
||||
<tr style="background:{$color}">
|
||||
<td>{$spaces}{$proc}</td>
|
||||
<td align="center">{$time}</td>
|
||||
</tr>
|
||||
EOD;
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<!-- start profiling callstack -->
|
||||
<table width="100%" cellpadding="2" style="border-spacing:1px;font:11px Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;color:#666666;">
|
||||
<tr>
|
||||
<th style="background:black;color:white;" colspan="2">
|
||||
Profiling Callstack Report
|
||||
</th>
|
||||
</tr>
|
||||
<tr style="background-color: #ccc;">
|
||||
<th>Procedure</th>
|
||||
<th>Time (s)</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach($data as $index=>$entry)
|
||||
{
|
||||
$color=($index%2)?'#F5F5F5':'#EBF8FE';
|
||||
list($proc,$time,$level)=$entry;
|
||||
$proc=CHtml::encode($proc);
|
||||
$time=sprintf('%0.5f',$time);
|
||||
$spaces=str_repeat(' ',$level*8);
|
||||
|
||||
echo <<<EOD
|
||||
<tr style="background:{$color}">
|
||||
<td>{$spaces}{$proc}</td>
|
||||
<td align="center">{$time}</td>
|
||||
</tr>
|
||||
EOD;
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<!-- end of profiling callstack -->
|
|
@ -1,22 +1,22 @@
|
|||
<script language="javascript" type="text/javascript">
|
||||
/*<![CDATA[*/
|
||||
if(typeof(console)=='object')
|
||||
{
|
||||
console.group("Profiling Summary Report");
|
||||
console.log(" count total average min max ");
|
||||
<?php
|
||||
foreach($data as $index=>$entry)
|
||||
{
|
||||
$proc=CJavaScript::quote($entry[0]);
|
||||
$count=sprintf('%5d',$entry[1]);
|
||||
$min=sprintf('%0.5f',$entry[2]);
|
||||
$max=sprintf('%0.5f',$entry[3]);
|
||||
$total=sprintf('%0.5f',$entry[4]);
|
||||
$average=sprintf('%0.5f',$entry[4]/$entry[1]);
|
||||
echo "\tconsole.log(\" $count $total $average $min $max {$proc}\");\n";
|
||||
}
|
||||
?>
|
||||
console.groupEnd();
|
||||
}
|
||||
/*]]>*/
|
||||
</script>
|
||||
<script language="javascript" type="text/javascript">
|
||||
/*<![CDATA[*/
|
||||
if(typeof(console)=='object')
|
||||
{
|
||||
console.group("Profiling Summary Report");
|
||||
console.log(" count total average min max ");
|
||||
<?php
|
||||
foreach($data as $index=>$entry)
|
||||
{
|
||||
$proc=CJavaScript::quote($entry[0]);
|
||||
$count=sprintf('%5d',$entry[1]);
|
||||
$min=sprintf('%0.5f',$entry[2]);
|
||||
$max=sprintf('%0.5f',$entry[3]);
|
||||
$total=sprintf('%0.5f',$entry[4]);
|
||||
$average=sprintf('%0.5f',$entry[4]/$entry[1]);
|
||||
echo "\tconsole.log(\" $count $total $average $min $max {$proc}\");\n";
|
||||
}
|
||||
?>
|
||||
console.groupEnd();
|
||||
}
|
||||
/*]]>*/
|
||||
</script>
|
||||
|
|
|
@ -1,41 +1,41 @@
|
|||
<!-- start profiling summary -->
|
||||
<table width="100%" cellpadding="2" style="border-spacing:1px;font:11px Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;color:#666666;">
|
||||
<tr>
|
||||
<th style="background:black;color:white;" colspan="6">
|
||||
Profiling Summary Report
|
||||
(Time: <?php echo sprintf('%0.5f',Yii::getLogger()->getExecutionTime()); ?>s,
|
||||
Memory: <?php echo number_format(Yii::getLogger()->getMemoryUsage()/1024); ?>KB)
|
||||
</th>
|
||||
</tr>
|
||||
<tr style="background-color: #ccc;">
|
||||
<th>Procedure</th>
|
||||
<th>Count</th>
|
||||
<th>Total (s)</th>
|
||||
<th>Avg. (s)</th>
|
||||
<th>Min. (s)</th>
|
||||
<th>Max. (s)</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach($data as $index=>$entry)
|
||||
{
|
||||
$color=($index%2)?'#F5F5F5':'#EBF8FE';
|
||||
$proc=CHtml::encode($entry[0]);
|
||||
$min=sprintf('%0.5f',$entry[2]);
|
||||
$max=sprintf('%0.5f',$entry[3]);
|
||||
$total=sprintf('%0.5f',$entry[4]);
|
||||
$average=sprintf('%0.5f',$entry[4]/$entry[1]);
|
||||
|
||||
echo <<<EOD
|
||||
<tr style="background:{$color}">
|
||||
<td>{$proc}</td>
|
||||
<td align="center">{$entry[1]}</td>
|
||||
<td align="center">{$total}</td>
|
||||
<td align="center">{$average}</td>
|
||||
<td align="center">{$min}</td>
|
||||
<td align="center">{$max}</td>
|
||||
</tr>
|
||||
EOD;
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<!-- start profiling summary -->
|
||||
<table width="100%" cellpadding="2" style="border-spacing:1px;font:11px Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;color:#666666;">
|
||||
<tr>
|
||||
<th style="background:black;color:white;" colspan="6">
|
||||
Profiling Summary Report
|
||||
(Time: <?php echo sprintf('%0.5f',Yii::getLogger()->getExecutionTime()); ?>s,
|
||||
Memory: <?php echo number_format(Yii::getLogger()->getMemoryUsage()/1024); ?>KB)
|
||||
</th>
|
||||
</tr>
|
||||
<tr style="background-color: #ccc;">
|
||||
<th>Procedure</th>
|
||||
<th>Count</th>
|
||||
<th>Total (s)</th>
|
||||
<th>Avg. (s)</th>
|
||||
<th>Min. (s)</th>
|
||||
<th>Max. (s)</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach($data as $index=>$entry)
|
||||
{
|
||||
$color=($index%2)?'#F5F5F5':'#EBF8FE';
|
||||
$proc=CHtml::encode($entry[0]);
|
||||
$min=sprintf('%0.5f',$entry[2]);
|
||||
$max=sprintf('%0.5f',$entry[3]);
|
||||
$total=sprintf('%0.5f',$entry[4]);
|
||||
$average=sprintf('%0.5f',$entry[4]/$entry[1]);
|
||||
|
||||
echo <<<EOD
|
||||
<tr style="background:{$color}">
|
||||
<td>{$proc}</td>
|
||||
<td align="center">{$entry[1]}</td>
|
||||
<td align="center">{$total}</td>
|
||||
<td align="center">{$average}</td>
|
||||
<td align="center">{$min}</td>
|
||||
<td align="center">{$max}</td>
|
||||
</tr>
|
||||
EOD;
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<!-- end of profiling summary -->
|
|
@ -11,7 +11,7 @@ foreach($data as $index=>$log) {
|
|||
$func='error';
|
||||
else
|
||||
$func='log';
|
||||
|
||||
|
||||
$content=CJavaScript::quote("[$time][$log[1]][$log[2]] $log[0]");
|
||||
echo "\tconsole.{$func}(\"{$content}\");\n";
|
||||
}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
<script language="javascript" type="text/javascript">
|
||||
/*<![CDATA[*/
|
||||
if(typeof(console)=='object') {
|
||||
console.group("Profiling Summary Report");
|
||||
console.log(" count total gem. min max ");
|
||||
<?php
|
||||
foreach($data as $index=>$entry) {
|
||||
$proc=CJavaScript::quote($entry[0]);
|
||||
$count=sprintf('%5d',$entry[1]);
|
||||
$min=sprintf('%0.5f',$entry[2]);
|
||||
$max=sprintf('%0.5f',$entry[3]);
|
||||
$total=sprintf('%0.5f',$entry[4]);
|
||||
$average=sprintf('%0.5f',$entry[4]/$entry[1]);
|
||||
echo "\tconsole.log(\" $count $total $average $min $max {$proc}\");\n";
|
||||
}
|
||||
?>
|
||||
console.groupEnd();
|
||||
}
|
||||
/*]]>*/
|
||||
<script language="javascript" type="text/javascript">
|
||||
/*<![CDATA[*/
|
||||
if(typeof(console)=='object') {
|
||||
console.group("Profiling Summary Report");
|
||||
console.log(" count total gem. min max ");
|
||||
<?php
|
||||
foreach($data as $index=>$entry) {
|
||||
$proc=CJavaScript::quote($entry[0]);
|
||||
$count=sprintf('%5d',$entry[1]);
|
||||
$min=sprintf('%0.5f',$entry[2]);
|
||||
$max=sprintf('%0.5f',$entry[3]);
|
||||
$total=sprintf('%0.5f',$entry[4]);
|
||||
$average=sprintf('%0.5f',$entry[4]/$entry[1]);
|
||||
echo "\tconsole.log(\" $count $total $average $min $max {$proc}\");\n";
|
||||
}
|
||||
?>
|
||||
console.groupEnd();
|
||||
}
|
||||
/*]]>*/
|
||||
</script>
|
|
@ -1,41 +1,41 @@
|
|||
<!-- start profiling summary -->
|
||||
<table width="100%" cellpadding="2" style="border-spacing:1px;font:11px Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;color:#666666;">
|
||||
<tr>
|
||||
<th style="background:black;color:white;" colspan="6">
|
||||
Profiling Samenvatting Rapport
|
||||
(Tijd: <?php echo sprintf('%0.5f',Yii::getLogger()->getExecutionTime()); ?>s,
|
||||
Geheugen: <?php echo number_format(Yii::getLogger()->getMemoryUsage()/1024); ?>KB)
|
||||
</th>
|
||||
</tr>
|
||||
<tr style="background-color: #ccc;">
|
||||
<th>Procedure</th>
|
||||
<th>Aantal</th>
|
||||
<th>Totaal (s)</th>
|
||||
<th>Gem. (s)</th>
|
||||
<th>Min. (s)</th>
|
||||
<th>Max. (s)</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach($data as $index=>$entry)
|
||||
{
|
||||
$color=($index%2)?'#F5F5F5':'#EBF8FE';
|
||||
$proc=CHtml::encode($entry[0]);
|
||||
$min=sprintf('%0.5f',$entry[2]);
|
||||
$max=sprintf('%0.5f',$entry[3]);
|
||||
$total=sprintf('%0.5f',$entry[4]);
|
||||
$average=sprintf('%0.5f',$entry[4]/$entry[1]);
|
||||
|
||||
echo <<<EOD
|
||||
<tr style="background:{$color}">
|
||||
<td>{$proc}</td>
|
||||
<td align="center">{$entry[1]}</td>
|
||||
<td align="center">{$total}</td>
|
||||
<td align="center">{$average}</td>
|
||||
<td align="center">{$min}</td>
|
||||
<td align="center">{$max}</td>
|
||||
</tr>
|
||||
EOD;
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<!-- start profiling summary -->
|
||||
<table width="100%" cellpadding="2" style="border-spacing:1px;font:11px Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;color:#666666;">
|
||||
<tr>
|
||||
<th style="background:black;color:white;" colspan="6">
|
||||
Profiling Samenvatting Rapport
|
||||
(Tijd: <?php echo sprintf('%0.5f',Yii::getLogger()->getExecutionTime()); ?>s,
|
||||
Geheugen: <?php echo number_format(Yii::getLogger()->getMemoryUsage()/1024); ?>KB)
|
||||
</th>
|
||||
</tr>
|
||||
<tr style="background-color: #ccc;">
|
||||
<th>Procedure</th>
|
||||
<th>Aantal</th>
|
||||
<th>Totaal (s)</th>
|
||||
<th>Gem. (s)</th>
|
||||
<th>Min. (s)</th>
|
||||
<th>Max. (s)</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach($data as $index=>$entry)
|
||||
{
|
||||
$color=($index%2)?'#F5F5F5':'#EBF8FE';
|
||||
$proc=CHtml::encode($entry[0]);
|
||||
$min=sprintf('%0.5f',$entry[2]);
|
||||
$max=sprintf('%0.5f',$entry[3]);
|
||||
$total=sprintf('%0.5f',$entry[4]);
|
||||
$average=sprintf('%0.5f',$entry[4]/$entry[1]);
|
||||
|
||||
echo <<<EOD
|
||||
<tr style="background:{$color}">
|
||||
<td>{$proc}</td>
|
||||
<td align="center">{$entry[1]}</td>
|
||||
<td align="center">{$total}</td>
|
||||
<td align="center">{$average}</td>
|
||||
<td align="center">{$min}</td>
|
||||
<td align="center">{$max}</td>
|
||||
</tr>
|
||||
EOD;
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<!-- end of profiling summary -->
|
|
@ -2,7 +2,7 @@
|
|||
<table width="100%" cellpadding="2" style="border-spacing:1px;font:11px Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;color:#666666;">
|
||||
<tr>
|
||||
<th style="background:black;color:white;" colspan="6">
|
||||
Relatorio Resumido de Profiling
|
||||
Relatorio Resumido de Profiling
|
||||
(Tempo: <?php echo sprintf('%0.5f',Yii::getLogger()->getExecutionTime()); ?>s,
|
||||
Memória: <?php echo number_format(Yii::getLogger()->getMemoryUsage()/1024); ?>KB)
|
||||
</th>
|
||||
|
|
|
@ -8,21 +8,21 @@
|
|||
<th>步骤</th>
|
||||
<th>时间 (秒)</th>
|
||||
</tr>
|
||||
<?php
|
||||
foreach ( $data as $index => $entry ) {
|
||||
$color = ($index % 2) ? '#F5F5F5' : '#EBF8FE';
|
||||
list ( $proc, $time, $level ) = $entry;
|
||||
$proc = CHtml::encode ( $proc );
|
||||
$time = sprintf ( '%0.5f', $time );
|
||||
$spaces = str_repeat ( ' ', $level * 8 );
|
||||
|
||||
<?php
|
||||
foreach ( $data as $index => $entry ) {
|
||||
$color = ($index % 2) ? '#F5F5F5' : '#EBF8FE';
|
||||
list ( $proc, $time, $level ) = $entry;
|
||||
$proc = CHtml::encode ( $proc );
|
||||
$time = sprintf ( '%0.5f', $time );
|
||||
$spaces = str_repeat ( ' ', $level * 8 );
|
||||
|
||||
echo <<<EOD
|
||||
<tr style="background:{$color}">
|
||||
<td>{$spaces}{$proc}</td>
|
||||
<td align="center">{$time}</td>
|
||||
</tr>
|
||||
EOD;
|
||||
}
|
||||
EOD;
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<!-- end of profiling callstack -->
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue