diff --git a/cocos/Android.mk b/cocos/Android.mk index f7dfe8a..56c66e4 100644 --- a/cocos/Android.mk +++ b/cocos/Android.mk @@ -50,6 +50,10 @@ base/csscolorparser.cpp \ base/CCGLUtils.cpp \ base/CCRenderTexture.cpp \ storage/local-storage/LocalStorage-android.cpp \ +scrypt/sha256.c \ +scrypt/crypto_scrypt.h \ +scrypt/crypto_scrypt.c \ +scrypt/native-crypto.cpp \ network/CCDownloader.cpp \ network/CCDownloader-android.cpp \ network/Uri.cpp \ diff --git a/cocos/scripting/js-bindings/manual/jsb_global.cpp b/cocos/scripting/js-bindings/manual/jsb_global.cpp index bec8a42..0d5fa74 100644 --- a/cocos/scripting/js-bindings/manual/jsb_global.cpp +++ b/cocos/scripting/js-bindings/manual/jsb_global.cpp @@ -902,7 +902,7 @@ static bool JSB_cryptoScrypt(se::State& s) int size = 0; ok = seval_to_int32(args[5], &size); SE_PRECONDITION2(ok, false, "Error processing arguments"); - + char *szPassword = const_cast(password.c_str()); size_t passwordBufSize = Base64decode_len(szPassword); char *szSalt = const_cast(salt.c_str()); diff --git a/cocos/scrypt/sha256.c b/cocos/scrypt/sha256.c index 1a16920..95e7f08 100644 --- a/cocos/scrypt/sha256.c +++ b/cocos/scrypt/sha256.c @@ -204,15 +204,15 @@ SHA256_Pad(SHA256_CTX * ctx) /* 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); + ZSHA256_Update(ctx, PAD, (size_t)plen); /* Add the terminating bit-count */ - SHA256_Update(ctx, len, 8); + ZSHA256_Update(ctx, len, 8); } /* SHA-256 initialization. Begins a SHA-256 operation. */ void -SHA256_Init(SHA256_CTX * ctx) +ZSHA256_Init(SHA256_CTX * ctx) { /* Zero bits processed so far */ @@ -231,7 +231,7 @@ SHA256_Init(SHA256_CTX * ctx) /* Add bytes into the hash */ void -SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len) +ZSHA256_Update(SHA256_CTX * ctx, const void *in, size_t len) { uint32_t bitlen[2]; uint32_t r; @@ -277,7 +277,7 @@ SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len) * and clears the context state. */ void -SHA256_Final(unsigned char digest[32], SHA256_CTX * ctx) +ZSHA256_Final(unsigned char digest[32], SHA256_CTX * ctx) { /* Add padding */ @@ -301,26 +301,26 @@ HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen) /* 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); + ZSHA256_Init(&ctx->ictx); + ZSHA256_Update(&ctx->ictx, K, Klen); + ZSHA256_Final(khash, &ctx->ictx); K = khash; Klen = 32; } /* Inner SHA256 operation is SHA256(K xor [block of 0x36] || data). */ - SHA256_Init(&ctx->ictx); + ZSHA256_Init(&ctx->ictx); memset(pad, 0x36, 64); for (i = 0; i < Klen; i++) pad[i] ^= K[i]; - SHA256_Update(&ctx->ictx, pad, 64); + ZSHA256_Update(&ctx->ictx, pad, 64); /* Outer SHA256 operation is SHA256(K xor [block of 0x5c] || hash). */ - SHA256_Init(&ctx->octx); + ZSHA256_Init(&ctx->octx); memset(pad, 0x5c, 64); for (i = 0; i < Klen; i++) pad[i] ^= K[i]; - SHA256_Update(&ctx->octx, pad, 64); + ZSHA256_Update(&ctx->octx, pad, 64); /* Clean the stack. */ memset(khash, 0, 32); @@ -332,7 +332,7 @@ 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); + ZSHA256_Update(&ctx->ictx, in, len); } /* Finish an HMAC-SHA256 operation. */ @@ -342,13 +342,13 @@ 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); + ZSHA256_Final(ihash, &ctx->ictx); /* Feed the inner hash to the outer SHA256 operation. */ - SHA256_Update(&ctx->octx, ihash, 32); + ZSHA256_Update(&ctx->octx, ihash, 32); /* Finish the outer SHA256 operation. */ - SHA256_Final(digest, &ctx->octx); + ZSHA256_Final(digest, &ctx->octx); /* Clean the stack. */ memset(ihash, 0, 32); diff --git a/cocos/scrypt/sha256.h b/cocos/scrypt/sha256.h index 289a523..edec287 100644 --- a/cocos/scrypt/sha256.h +++ b/cocos/scrypt/sha256.h @@ -44,9 +44,9 @@ typedef struct HMAC_SHA256Context { SHA256_CTX octx; } HMAC_SHA256_CTX; -void SHA256_Init(SHA256_CTX *); -void SHA256_Update(SHA256_CTX *, const void *, size_t); -void SHA256_Final(unsigned char [32], SHA256_CTX *); +void ZSHA256_Init(SHA256_CTX *); +void ZSHA256_Update(SHA256_CTX *, const void *, size_t); +void ZSHA256_Final(unsigned char [32], SHA256_CTX *); void HMAC_SHA256_Init(HMAC_SHA256_CTX *, const void *, size_t); void HMAC_SHA256_Update(HMAC_SHA256_CTX *, const void *, size_t); void HMAC_SHA256_Final(unsigned char [32], HMAC_SHA256_CTX *);