Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
33aa4ca4
Commit
33aa4ca4
authored
Jul 01, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move libmincrypt into separate repo
parent
05658caf
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
8 additions
and
3022 deletions
+8
-3022
.gitmodules
.gitmodules
+3
-0
Android.mk
native/jni/Android.mk
+2
-0
Android.mk
native/jni/external/Android.mk
+2
-14
dsa_sig.h
native/jni/external/include/mincrypt/dsa_sig.h
+0
-43
hash-internal.h
native/jni/external/include/mincrypt/hash-internal.h
+0
-63
p256.h
native/jni/external/include/mincrypt/p256.h
+0
-162
p256_ecdsa.h
native/jni/external/include/mincrypt/p256_ecdsa.h
+0
-53
rsa.h
native/jni/external/include/mincrypt/rsa.h
+0
-58
sha.h
native/jni/external/include/mincrypt/sha.h
+0
-52
sha256.h
native/jni/external/include/mincrypt/sha256.h
+0
-52
sha1.h
native/jni/external/include/sha1.h
+0
-44
mincrypt
native/jni/external/mincrypt
+1
-0
dsa_sig.c
native/jni/external/mincrypt/dsa_sig.c
+0
-126
p256.c
native/jni/external/mincrypt/p256.c
+0
-373
p256_ec.c
native/jni/external/mincrypt/p256_ec.c
+0
-1279
p256_ecdsa.c
native/jni/external/mincrypt/p256_ecdsa.c
+0
-56
rsa.c
native/jni/external/mincrypt/rsa.c
+0
-308
sha.c
native/jni/external/mincrypt/sha.c
+0
-155
sha256.c
native/jni/external/mincrypt/sha256.c
+0
-184
No files found.
.gitmodules
View file @
33aa4ca4
...
@@ -19,3 +19,6 @@
...
@@ -19,3 +19,6 @@
[submodule "nanopb"]
[submodule "nanopb"]
path = native/jni/external/nanopb
path = native/jni/external/nanopb
url = https://github.com/nanopb/nanopb.git
url = https://github.com/nanopb/nanopb.git
[submodule "mincrypt"]
path = native/jni/external/mincrypt
url = https://github.com/topjohnwu/mincrypt.git
native/jni/Android.mk
View file @
33aa4ca4
...
@@ -12,6 +12,7 @@ LIBFDT := $(EXT_PATH)/dtc/libfdt
...
@@ -12,6 +12,7 @@ LIBFDT := $(EXT_PATH)/dtc/libfdt
LIBNANOPB := $(EXT_PATH)/nanopb
LIBNANOPB := $(EXT_PATH)/nanopb
LIBSYSTEMPROPERTIES := jni/systemproperties/include
LIBSYSTEMPROPERTIES := jni/systemproperties/include
LIBUTILS := jni/utils/include
LIBUTILS := jni/utils/include
LIBMINCRYPT := $(EXT_PATH)/mincrypt/include
########################
########################
# Binaries
# Binaries
...
@@ -127,6 +128,7 @@ LOCAL_STATIC_LIBRARIES := libmincrypt liblzma liblz4 libbz2 libfdt libutils
...
@@ -127,6 +128,7 @@ LOCAL_STATIC_LIBRARIES := libmincrypt liblzma liblz4 libbz2 libfdt libutils
LOCAL_C_INCLUDES := \
LOCAL_C_INCLUDES := \
jni/include \
jni/include \
$(EXT_PATH)/include \
$(EXT_PATH)/include \
$(LIBMINCRYPT) \
$(LIBLZMA) \
$(LIBLZMA) \
$(LIBLZ4) \
$(LIBLZ4) \
$(LIBBZ2) \
$(LIBBZ2) \
...
...
native/jni/external/Android.mk
View file @
33aa4ca4
...
@@ -28,20 +28,6 @@ LOCAL_SRC_FILES := \
...
@@ -28,20 +28,6 @@ LOCAL_SRC_FILES := \
xz-embedded/xz_dec_stream.c
xz-embedded/xz_dec_stream.c
include $(BUILD_STATIC_LIBRARY)
include $(BUILD_STATIC_LIBRARY)
# libmincrypt.a
include $(CLEAR_VARS)
LOCAL_MODULE:= libmincrypt
LOCAL_C_INCLUDES := $(EXT_PATH)/include
LOCAL_SRC_FILES := \
mincrypt/dsa_sig.c \
mincrypt/p256.c \
mincrypt/p256_ec.c \
mincrypt/p256_ecdsa.c \
mincrypt/rsa.c \
mincrypt/sha.c \
mincrypt/sha256.c
include $(BUILD_STATIC_LIBRARY)
# libnanopb.a
# libnanopb.a
include $(CLEAR_VARS)
include $(CLEAR_VARS)
LOCAL_MODULE:= libnanopb
LOCAL_MODULE:= libnanopb
...
@@ -265,3 +251,5 @@ LOCAL_SRC_FILES := \
...
@@ -265,3 +251,5 @@ LOCAL_SRC_FILES := \
selinux/libsepol/cil/src/cil_post.c
selinux/libsepol/cil/src/cil_post.c
LOCAL_CFLAGS += -Dgetline=__getline -Wno-implicit-function-declaration
LOCAL_CFLAGS += -Dgetline=__getline -Wno-implicit-function-declaration
include $(BUILD_STATIC_LIBRARY)
include $(BUILD_STATIC_LIBRARY)
include $(EXT_PATH)/mincrypt/Android.mk
native/jni/external/include/mincrypt/dsa_sig.h
deleted
100644 → 0
View file @
05658caf
/*
* Copyright 2013 The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Google Inc. ``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 Google Inc. 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.
*/
#ifndef SYSTEM_CORE_INCLUDE_MINCRYPT_DSA_SIG_H_
#define SYSTEM_CORE_INCLUDE_MINCRYPT_DSA_SIG_H_
#include "mincrypt/p256.h"
#ifdef __cplusplus
extern
"C"
{
#endif
// Returns 0 if input sig is not a valid ASN.1 sequence
int
dsa_sig_unpack
(
unsigned
char
*
sig
,
int
sig_len
,
p256_int
*
r_int
,
p256_int
*
s_int
);
#ifdef __cplusplus
}
#endif
#endif
/* SYSTEM_CORE_INCLUDE_MINCRYPT_DSA_SIG_H_ */
native/jni/external/include/mincrypt/hash-internal.h
deleted
100644 → 0
View file @
05658caf
/*
* Copyright 2007 The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Google Inc. ``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 Google Inc. 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.
*/
#ifndef SYSTEM_CORE_INCLUDE_MINCRYPT_HASH_INTERNAL_H_
#define SYSTEM_CORE_INCLUDE_MINCRYPT_HASH_INTERNAL_H_
#include <stdint.h>
#ifdef __cplusplus
extern
"C"
{
#endif // __cplusplus
struct
HASH_CTX
;
// forward decl
typedef
struct
HASH_VTAB
{
void
(
*
const
init
)(
struct
HASH_CTX
*
);
void
(
*
const
update
)(
struct
HASH_CTX
*
,
const
void
*
,
int
);
const
uint8_t
*
(
*
const
final
)(
struct
HASH_CTX
*
);
const
uint8_t
*
(
*
const
hash
)(
const
void
*
,
int
,
uint8_t
*
);
int
size
;
}
HASH_VTAB
;
typedef
struct
HASH_CTX
{
const
HASH_VTAB
*
f
;
uint64_t
count
;
uint8_t
buf
[
64
];
uint32_t
state
[
8
];
// upto SHA2
}
HASH_CTX
;
#define HASH_init(ctx) (ctx)->f->init(ctx)
#define HASH_update(ctx, data, len) (ctx)->f->update(ctx, data, len)
#define HASH_final(ctx) (ctx)->f->final(ctx)
#define HASH_hash(data, len, digest) (ctx)->f->hash(data, len, digest)
#define HASH_size(ctx) (ctx)->f->size
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // SYSTEM_CORE_INCLUDE_MINCRYPT_HASH_INTERNAL_H_
native/jni/external/include/mincrypt/p256.h
deleted
100644 → 0
View file @
05658caf
/*
* Copyright 2013 The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Google Inc. ``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 Google Inc. 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.
*/
#ifndef SYSTEM_CORE_INCLUDE_MINCRYPT_LITE_P256_H_
#define SYSTEM_CORE_INCLUDE_MINCRYPT_LITE_P256_H_
// Collection of routines manipulating 256 bit unsigned integers.
// Just enough to implement ecdsa-p256 and related algorithms.
#include <stdint.h>
#ifdef __cplusplus
extern
"C"
{
#endif
#define P256_BITSPERDIGIT 32
#define P256_NDIGITS 8
#define P256_NBYTES 32
typedef
int
p256_err
;
typedef
uint32_t
p256_digit
;
typedef
int32_t
p256_sdigit
;
typedef
uint64_t
p256_ddigit
;
typedef
int64_t
p256_sddigit
;
// Defining p256_int as struct to leverage struct assigment.
typedef
struct
{
p256_digit
a
[
P256_NDIGITS
];
}
p256_int
;
extern
const
p256_int
SECP256r1_n
;
// Curve order
extern
const
p256_int
SECP256r1_p
;
// Curve prime
extern
const
p256_int
SECP256r1_b
;
// Curve param
// Initialize a p256_int to zero.
void
p256_init
(
p256_int
*
a
);
// Clear a p256_int to zero.
void
p256_clear
(
p256_int
*
a
);
// Return bit. Index 0 is least significant.
int
p256_get_bit
(
const
p256_int
*
a
,
int
index
);
// b := a % MOD
void
p256_mod
(
const
p256_int
*
MOD
,
const
p256_int
*
a
,
p256_int
*
b
);
// c := a * (top_b | b) % MOD
void
p256_modmul
(
const
p256_int
*
MOD
,
const
p256_int
*
a
,
const
p256_digit
top_b
,
const
p256_int
*
b
,
p256_int
*
c
);
// b := 1 / a % MOD
// MOD best be SECP256r1_n
void
p256_modinv
(
const
p256_int
*
MOD
,
const
p256_int
*
a
,
p256_int
*
b
);
// b := 1 / a % MOD
// MOD best be SECP256r1_n
// Faster than p256_modinv()
void
p256_modinv_vartime
(
const
p256_int
*
MOD
,
const
p256_int
*
a
,
p256_int
*
b
);
// b := a << (n % P256_BITSPERDIGIT)
// Returns the bits shifted out of most significant digit.
p256_digit
p256_shl
(
const
p256_int
*
a
,
int
n
,
p256_int
*
b
);
// b := a >> (n % P256_BITSPERDIGIT)
void
p256_shr
(
const
p256_int
*
a
,
int
n
,
p256_int
*
b
);
int
p256_is_zero
(
const
p256_int
*
a
);
int
p256_is_odd
(
const
p256_int
*
a
);
int
p256_is_even
(
const
p256_int
*
a
);
// Returns -1, 0 or 1.
int
p256_cmp
(
const
p256_int
*
a
,
const
p256_int
*
b
);
// c: = a - b
// Returns -1 on borrow.
int
p256_sub
(
const
p256_int
*
a
,
const
p256_int
*
b
,
p256_int
*
c
);
// c := a + b
// Returns 1 on carry.
int
p256_add
(
const
p256_int
*
a
,
const
p256_int
*
b
,
p256_int
*
c
);
// c := a + (single digit)b
// Returns carry 1 on carry.
int
p256_add_d
(
const
p256_int
*
a
,
p256_digit
b
,
p256_int
*
c
);
// ec routines.
// {out_x,out_y} := nG
void
p256_base_point_mul
(
const
p256_int
*
n
,
p256_int
*
out_x
,
p256_int
*
out_y
);
// {out_x,out_y} := n{in_x,in_y}
void
p256_point_mul
(
const
p256_int
*
n
,
const
p256_int
*
in_x
,
const
p256_int
*
in_y
,
p256_int
*
out_x
,
p256_int
*
out_y
);
// {out_x,out_y} := n1G + n2{in_x,in_y}
void
p256_points_mul_vartime
(
const
p256_int
*
n1
,
const
p256_int
*
n2
,
const
p256_int
*
in_x
,
const
p256_int
*
in_y
,
p256_int
*
out_x
,
p256_int
*
out_y
);
// Return whether point {x,y} is on curve.
int
p256_is_valid_point
(
const
p256_int
*
x
,
const
p256_int
*
y
);
// Outputs big-endian binary form. No leading zero skips.
void
p256_to_bin
(
const
p256_int
*
src
,
uint8_t
dst
[
P256_NBYTES
]);
// Reads from big-endian binary form,
// thus pre-pad with leading zeros if short.
void
p256_from_bin
(
const
uint8_t
src
[
P256_NBYTES
],
p256_int
*
dst
);
#define P256_DIGITS(x) ((x)->a)
#define P256_DIGIT(x,y) ((x)->a[y])
#define P256_ZERO {{0}}
#define P256_ONE {{1}}
#ifdef __cplusplus
}
#endif
#endif // SYSTEM_CORE_INCLUDE_MINCRYPT_LITE_P256_H_
native/jni/external/include/mincrypt/p256_ecdsa.h
deleted
100644 → 0
View file @
05658caf
/*
* Copyright 2013 The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Google Inc. ``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 Google Inc. 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.
*/
#ifndef SYSTEM_CORE_INCLUDE_MINCRYPT_P256_ECDSA_H_
#define SYSTEM_CORE_INCLUDE_MINCRYPT_P256_ECDSA_H_
// Using current directory as relative include path here since
// this code typically gets lifted into a variety of build systems
// and directory structures.
#include "p256.h"
#ifdef __cplusplus
extern
"C"
{
#endif
// Returns 0 if {r,s} is not a signature on message for
// public key {key_x,key_y}.
//
// Note: message is a p256_int.
// Convert from a binary string using p256_from_bin().
int
p256_ecdsa_verify
(
const
p256_int
*
key_x
,
const
p256_int
*
key_y
,
const
p256_int
*
message
,
const
p256_int
*
r
,
const
p256_int
*
s
);
#ifdef __cplusplus
}
#endif
#endif // SYSTEM_CORE_INCLUDE_MINCRYPT_P256_ECDSA_H_
native/jni/external/include/mincrypt/rsa.h
deleted
100644 → 0
View file @
05658caf
/* rsa.h
**
** Copyright 2008, The Android Open Source Project
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * 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.
** * Neither the name of Google Inc. nor the names of its contributors may
** be used to endorse or promote products derived from this software
** without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY Google Inc. ``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 Google Inc. 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.
*/
#ifndef SYSTEM_CORE_INCLUDE_MINCRYPT_RSA_H_
#define SYSTEM_CORE_INCLUDE_MINCRYPT_RSA_H_
#include <inttypes.h>
#ifdef __cplusplus
extern
"C"
{
#endif
#define RSANUMBYTES 256
/* 2048 bit key length */
#define RSANUMWORDS (RSANUMBYTES / sizeof(uint32_t))
typedef
struct
RSAPublicKey
{
int
len
;
/* Length of n[] in number of uint32_t */
uint32_t
n0inv
;
/* -1 / n[0] mod 2^32 */
uint32_t
n
[
RSANUMWORDS
];
/* modulus as little endian array */
uint32_t
rr
[
RSANUMWORDS
];
/* R^2 as little endian array */
int
exponent
;
/* 3 or 65537 */
}
RSAPublicKey
;
int
RSA_verify
(
const
RSAPublicKey
*
key
,
const
uint8_t
*
signature
,
const
int
len
,
const
uint8_t
*
hash
,
const
int
hash_len
);
#ifdef __cplusplus
}
#endif
#endif // SYSTEM_CORE_INCLUDE_MINCRYPT_RSA_H_
native/jni/external/include/mincrypt/sha.h
deleted
100644 → 0
View file @
05658caf
/*
* Copyright 2005 The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Google Inc. ``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 Google Inc. 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.
*/
#ifndef SYSTEM_CORE_INCLUDE_MINCRYPT_SHA1_H_
#define SYSTEM_CORE_INCLUDE_MINCRYPT_SHA1_H_
#include <stdint.h>
#include "hash-internal.h"
#ifdef __cplusplus
extern
"C"
{
#endif // __cplusplus
typedef
HASH_CTX
SHA_CTX
;
void
SHA_init
(
SHA_CTX
*
ctx
);
void
SHA_update
(
SHA_CTX
*
ctx
,
const
void
*
data
,
int
len
);
const
uint8_t
*
SHA_final
(
SHA_CTX
*
ctx
);
// Convenience method. Returns digest address.
// NOTE: *digest needs to hold SHA_DIGEST_SIZE bytes.
const
uint8_t
*
SHA_hash
(
const
void
*
data
,
int
len
,
uint8_t
*
digest
);
#define SHA_DIGEST_SIZE 20
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // SYSTEM_CORE_INCLUDE_MINCRYPT_SHA1_H_
native/jni/external/include/mincrypt/sha256.h
deleted
100644 → 0
View file @
05658caf
/*
* Copyright 2011 The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Google Inc. ``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 Google Inc. 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.
*/
#ifndef SYSTEM_CORE_INCLUDE_MINCRYPT_SHA256_H_
#define SYSTEM_CORE_INCLUDE_MINCRYPT_SHA256_H_
#include <stdint.h>
#include "hash-internal.h"
#ifdef __cplusplus
extern
"C"
{
#endif // __cplusplus
typedef
HASH_CTX
SHA256_CTX
;
void
SHA256_init
(
SHA256_CTX
*
ctx
);
void
SHA256_update
(
SHA256_CTX
*
ctx
,
const
void
*
data
,
int
len
);
const
uint8_t
*
SHA256_final
(
SHA256_CTX
*
ctx
);
// Convenience method. Returns digest address.
const
uint8_t
*
SHA256_hash
(
const
void
*
data
,
int
len
,
uint8_t
*
digest
);
#define SHA256_DIGEST_SIZE 32
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // SYSTEM_CORE_INCLUDE_MINCRYPT_SHA256_H_
native/jni/external/include/sha1.h
deleted
100644 → 0
View file @
05658caf
#ifndef SHA1_H
#define SHA1_H
/*
SHA-1 in C
By Steve Reid <steve@edmweb.com>
100% Public Domain
*/
#include "stdint.h"
typedef
struct
{
uint32_t
state
[
5
];
uint32_t
count
[
2
];
unsigned
char
buffer
[
64
];
}
SHA1_CTX
;
void
SHA1Transform
(
uint32_t
state
[
5
],
const
unsigned
char
buffer
[
64
]
);
void
SHA1Init
(
SHA1_CTX
*
context
);
void
SHA1Update
(
SHA1_CTX
*
context
,
const
unsigned
char
*
data
,
uint32_t
len
);
void
SHA1Final
(
unsigned
char
digest
[
20
],
SHA1_CTX
*
context
);
void
SHA1
(
char
*
hash_out
,
const
char
*
str
,
int
len
);
#endif
/* SHA1_H */
mincrypt
@
ac33afa7
Subproject commit ac33afa79e57e198b9eeec231140d64816a0bb1e
native/jni/external/mincrypt/dsa_sig.c
deleted
100644 → 0
View file @
05658caf
/*
* Copyright 2013 The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Google Inc. ``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 Google Inc. 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.
*/
#include <string.h>
#include "mincrypt/dsa_sig.h"
#include "mincrypt/p256.h"
/**
* Trims off the leading zero bytes and copy it to a buffer aligning it to the end.
*/
static
inline
int
trim_to_p256_bytes
(
unsigned
char
dst
[
P256_NBYTES
],
unsigned
char
*
src
,
int
src_len
)
{
int
dst_offset
;
while
(
*
src
==
'\0'
&&
src_len
>
0
)
{
src
++
;
src_len
--
;
}
if
(
src_len
>
P256_NBYTES
||
src_len
<
1
)
{
return
0
;
}
dst_offset
=
P256_NBYTES
-
src_len
;
memset
(
dst
,
0
,
dst_offset
);
memcpy
(
dst
+
dst_offset
,
src
,
src_len
);
return
1
;
}
/**
* Unpacks the ASN.1 DSA signature sequence.
*/
int
dsa_sig_unpack
(
unsigned
char
*
sig
,
int
sig_len
,
p256_int
*
r_int
,
p256_int
*
s_int
)
{
/*
* Structure is:
* 0x30 0xNN SEQUENCE + s_length
* 0x02 0xNN INTEGER + r_length
* 0xAA 0xBB .. r_length bytes of "r" (offset 4)
* 0x02 0xNN INTEGER + s_length
* 0xMM 0xNN .. s_length bytes of "s" (offset 6 + r_len)
*/
int
seq_len
;
unsigned
char
r_bytes
[
P256_NBYTES
];
unsigned
char
s_bytes
[
P256_NBYTES
];
int
r_len
;
int
s_len
;
memset
(
r_bytes
,
0
,
sizeof
(
r_bytes
));
memset
(
s_bytes
,
0
,
sizeof
(
s_bytes
));
/*
* Must have at least:
* 2 bytes sequence header and length
* 2 bytes R integer header and length
* 1 byte of R
* 2 bytes S integer header and length
* 1 byte of S
*
* 8 bytes total
*/
if
(
sig_len
<
8
||
sig
[
0
]
!=
0x30
||
sig
[
2
]
!=
0x02
)
{
return
0
;
}
seq_len
=
sig
[
1
];
if
((
seq_len
<=
0
)
||
(
seq_len
+
2
!=
sig_len
))
{
return
0
;
}
r_len
=
sig
[
3
];
/*
* Must have at least:
* 2 bytes for R header and length
* 2 bytes S integer header and length
* 1 byte of S
*/
if
((
r_len
<
1
)
||
(
r_len
>
seq_len
-
5
)
||
(
sig
[
4
+
r_len
]
!=
0x02
))
{
return
0
;
}
s_len
=
sig
[
5
+
r_len
];
/**
* Must have:
* 2 bytes for R header and length
* r_len bytes for R
* 2 bytes S integer header and length
*/
if
((
s_len
<
1
)
||
(
s_len
!=
seq_len
-
4
-
r_len
))
{
return
0
;
}
/*
* ASN.1 encoded integers are zero-padded for positive integers. Make sure we have
* a correctly-sized buffer and that the resulting integer isn't too large.
*/
if
(
!
trim_to_p256_bytes
(
r_bytes
,
&
sig
[
4
],
r_len
)
||
!
trim_to_p256_bytes
(
s_bytes
,
&
sig
[
6
+
r_len
],
s_len
))
{
return
0
;
}
p256_from_bin
(
r_bytes
,
r_int
);
p256_from_bin
(
s_bytes
,
s_int
);
return
1
;
}
native/jni/external/mincrypt/p256.c
deleted
100644 → 0
View file @
05658caf
This diff is collapsed.
Click to expand it.
native/jni/external/mincrypt/p256_ec.c
deleted
100644 → 0
View file @
05658caf
This diff is collapsed.
Click to expand it.
native/jni/external/mincrypt/p256_ecdsa.c
deleted
100644 → 0
View file @
05658caf
/*
* Copyright 2013 The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Google Inc. ``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 Google Inc. 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.
*/
#include <string.h>
#include "mincrypt/p256_ecdsa.h"
#include "mincrypt/p256.h"
int
p256_ecdsa_verify
(
const
p256_int
*
key_x
,
const
p256_int
*
key_y
,
const
p256_int
*
message
,
const
p256_int
*
r
,
const
p256_int
*
s
)
{
p256_int
u
,
v
;
// Check public key.
if
(
!
p256_is_valid_point
(
key_x
,
key_y
))
return
0
;
// Check r and s are != 0 % n.
p256_mod
(
&
SECP256r1_n
,
r
,
&
u
);
p256_mod
(
&
SECP256r1_n
,
s
,
&
v
);
if
(
p256_is_zero
(
&
u
)
||
p256_is_zero
(
&
v
))
return
0
;
p256_modinv_vartime
(
&
SECP256r1_n
,
s
,
&
v
);
p256_modmul
(
&
SECP256r1_n
,
message
,
0
,
&
v
,
&
u
);
// message / s % n
p256_modmul
(
&
SECP256r1_n
,
r
,
0
,
&
v
,
&
v
);
// r / s % n
p256_points_mul_vartime
(
&
u
,
&
v
,
key_x
,
key_y
,
&
u
,
&
v
);
p256_mod
(
&
SECP256r1_n
,
&
u
,
&
u
);
// (x coord % p) % n
return
p256_cmp
(
r
,
&
u
)
==
0
;
}
native/jni/external/mincrypt/rsa.c
deleted
100644 → 0
View file @
05658caf
This diff is collapsed.
Click to expand it.
native/jni/external/mincrypt/sha.c
deleted
100644 → 0
View file @
05658caf
/* sha.c
**
** Copyright 2013, The Android Open Source Project
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * 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.
** * Neither the name of Google Inc. nor the names of its contributors may
** be used to endorse or promote products derived from this software
** without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY Google Inc. ``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 Google Inc. 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.
*/
// Optimized for minimal code size.
#include "mincrypt/sha.h"
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#define rol(bits, value) (((value) << (bits)) | ((value) >> (32 - (bits))))
static
void
SHA1_Transform
(
SHA_CTX
*
ctx
)
{
uint32_t
W
[
80
];
uint32_t
A
,
B
,
C
,
D
,
E
;
uint8_t
*
p
=
ctx
->
buf
;
int
t
;
for
(
t
=
0
;
t
<
16
;
++
t
)
{
uint32_t
tmp
=
*
p
++
<<
24
;
tmp
|=
*
p
++
<<
16
;
tmp
|=
*
p
++
<<
8
;
tmp
|=
*
p
++
;
W
[
t
]
=
tmp
;
}
for
(;
t
<
80
;
t
++
)
{
W
[
t
]
=
rol
(
1
,
W
[
t
-
3
]
^
W
[
t
-
8
]
^
W
[
t
-
14
]
^
W
[
t
-
16
]);
}
A
=
ctx
->
state
[
0
];
B
=
ctx
->
state
[
1
];
C
=
ctx
->
state
[
2
];
D
=
ctx
->
state
[
3
];
E
=
ctx
->
state
[
4
];
for
(
t
=
0
;
t
<
80
;
t
++
)
{
uint32_t
tmp
=
rol
(
5
,
A
)
+
E
+
W
[
t
];
if
(
t
<
20
)
tmp
+=
(
D
^
(
B
&
(
C
^
D
)))
+
0x5A827999
;
else
if
(
t
<
40
)
tmp
+=
(
B
^
C
^
D
)
+
0x6ED9EBA1
;
else
if
(
t
<
60
)
tmp
+=
((
B
&
C
)
|
(
D
&
(
B
|
C
)))
+
0x8F1BBCDC
;
else
tmp
+=
(
B
^
C
^
D
)
+
0xCA62C1D6
;
E
=
D
;
D
=
C
;
C
=
rol
(
30
,
B
);
B
=
A
;
A
=
tmp
;
}
ctx
->
state
[
0
]
+=
A
;
ctx
->
state
[
1
]
+=
B
;
ctx
->
state
[
2
]
+=
C
;
ctx
->
state
[
3
]
+=
D
;
ctx
->
state
[
4
]
+=
E
;
}
static
const
HASH_VTAB
SHA_VTAB
=
{
SHA_init
,
SHA_update
,
SHA_final
,
SHA_hash
,
SHA_DIGEST_SIZE
};
void
SHA_init
(
SHA_CTX
*
ctx
)
{
ctx
->
f
=
&
SHA_VTAB
;
ctx
->
state
[
0
]
=
0x67452301
;
ctx
->
state
[
1
]
=
0xEFCDAB89
;
ctx
->
state
[
2
]
=
0x98BADCFE
;
ctx
->
state
[
3
]
=
0x10325476
;
ctx
->
state
[
4
]
=
0xC3D2E1F0
;
ctx
->
count
=
0
;
}
void
SHA_update
(
SHA_CTX
*
ctx
,
const
void
*
data
,
int
len
)
{
int
i
=
(
int
)
(
ctx
->
count
&
63
);
const
uint8_t
*
p
=
(
const
uint8_t
*
)
data
;
ctx
->
count
+=
len
;
while
(
len
--
)
{
ctx
->
buf
[
i
++
]
=
*
p
++
;
if
(
i
==
64
)
{
SHA1_Transform
(
ctx
);
i
=
0
;
}
}
}
const
uint8_t
*
SHA_final
(
SHA_CTX
*
ctx
)
{
uint8_t
*
p
=
ctx
->
buf
;
uint64_t
cnt
=
ctx
->
count
*
8
;
int
i
;
SHA_update
(
ctx
,
(
uint8_t
*
)
"
\x80
"
,
1
);
while
((
ctx
->
count
&
63
)
!=
56
)
{
SHA_update
(
ctx
,
(
uint8_t
*
)
"
\0
"
,
1
);
}
for
(
i
=
0
;
i
<
8
;
++
i
)
{
uint8_t
tmp
=
(
uint8_t
)
(
cnt
>>
((
7
-
i
)
*
8
));
SHA_update
(
ctx
,
&
tmp
,
1
);
}
for
(
i
=
0
;
i
<
5
;
i
++
)
{
uint32_t
tmp
=
ctx
->
state
[
i
];
*
p
++
=
tmp
>>
24
;
*
p
++
=
tmp
>>
16
;
*
p
++
=
tmp
>>
8
;
*
p
++
=
tmp
>>
0
;
}
return
ctx
->
buf
;
}
/* Convenience function */
const
uint8_t
*
SHA_hash
(
const
void
*
data
,
int
len
,
uint8_t
*
digest
)
{
SHA_CTX
ctx
;
SHA_init
(
&
ctx
);
SHA_update
(
&
ctx
,
data
,
len
);
memcpy
(
digest
,
SHA_final
(
&
ctx
),
SHA_DIGEST_SIZE
);
return
digest
;
}
native/jni/external/mincrypt/sha256.c
deleted
100644 → 0
View file @
05658caf
/* sha256.c
**
** Copyright 2013, The Android Open Source Project
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * 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.
** * Neither the name of Google Inc. nor the names of its contributors may
** be used to endorse or promote products derived from this software
** without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY Google Inc. ``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 Google Inc. 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.
*/
// Optimized for minimal code size.
#include "mincrypt/sha256.h"
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#define ror(value, bits) (((value) >> (bits)) | ((value) << (32 - (bits))))
#define shr(value, bits) ((value) >> (bits))
static
const
uint32_t
K
[
64
]
=
{
0x428a2f98
,
0x71374491
,
0xb5c0fbcf
,
0xe9b5dba5
,
0x3956c25b
,
0x59f111f1
,
0x923f82a4
,
0xab1c5ed5
,
0xd807aa98
,
0x12835b01
,
0x243185be
,
0x550c7dc3
,
0x72be5d74
,
0x80deb1fe
,
0x9bdc06a7
,
0xc19bf174
,
0xe49b69c1
,
0xefbe4786
,
0x0fc19dc6
,
0x240ca1cc
,
0x2de92c6f
,
0x4a7484aa
,
0x5cb0a9dc
,
0x76f988da
,
0x983e5152
,
0xa831c66d
,
0xb00327c8
,
0xbf597fc7
,
0xc6e00bf3
,
0xd5a79147
,
0x06ca6351
,
0x14292967
,
0x27b70a85
,
0x2e1b2138
,
0x4d2c6dfc
,
0x53380d13
,
0x650a7354
,
0x766a0abb
,
0x81c2c92e
,
0x92722c85
,
0xa2bfe8a1
,
0xa81a664b
,
0xc24b8b70
,
0xc76c51a3
,
0xd192e819
,
0xd6990624
,
0xf40e3585
,
0x106aa070
,
0x19a4c116
,
0x1e376c08
,
0x2748774c
,
0x34b0bcb5
,
0x391c0cb3
,
0x4ed8aa4a
,
0x5b9cca4f
,
0x682e6ff3
,
0x748f82ee
,
0x78a5636f
,
0x84c87814
,
0x8cc70208
,
0x90befffa
,
0xa4506ceb
,
0xbef9a3f7
,
0xc67178f2
};
static
void
SHA256_Transform
(
SHA256_CTX
*
ctx
)
{
uint32_t
W
[
64
];
uint32_t
A
,
B
,
C
,
D
,
E
,
F
,
G
,
H
;
uint8_t
*
p
=
ctx
->
buf
;
int
t
;
for
(
t
=
0
;
t
<
16
;
++
t
)
{
uint32_t
tmp
=
*
p
++
<<
24
;
tmp
|=
*
p
++
<<
16
;
tmp
|=
*
p
++
<<
8
;
tmp
|=
*
p
++
;
W
[
t
]
=
tmp
;
}
for
(;
t
<
64
;
t
++
)
{
uint32_t
s0
=
ror
(
W
[
t
-
15
],
7
)
^
ror
(
W
[
t
-
15
],
18
)
^
shr
(
W
[
t
-
15
],
3
);
uint32_t
s1
=
ror
(
W
[
t
-
2
],
17
)
^
ror
(
W
[
t
-
2
],
19
)
^
shr
(
W
[
t
-
2
],
10
);
W
[
t
]
=
W
[
t
-
16
]
+
s0
+
W
[
t
-
7
]
+
s1
;
}
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
];
for
(
t
=
0
;
t
<
64
;
t
++
)
{
uint32_t
s0
=
ror
(
A
,
2
)
^
ror
(
A
,
13
)
^
ror
(
A
,
22
);
uint32_t
maj
=
(
A
&
B
)
^
(
A
&
C
)
^
(
B
&
C
);
uint32_t
t2
=
s0
+
maj
;
uint32_t
s1
=
ror
(
E
,
6
)
^
ror
(
E
,
11
)
^
ror
(
E
,
25
);
uint32_t
ch
=
(
E
&
F
)
^
((
~
E
)
&
G
);
uint32_t
t1
=
H
+
s1
+
ch
+
K
[
t
]
+
W
[
t
];
H
=
G
;
G
=
F
;
F
=
E
;
E
=
D
+
t1
;
D
=
C
;
C
=
B
;
B
=
A
;
A
=
t1
+
t2
;
}
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
;
}
static
const
HASH_VTAB
SHA256_VTAB
=
{
SHA256_init
,
SHA256_update
,
SHA256_final
,
SHA256_hash
,
SHA256_DIGEST_SIZE
};
void
SHA256_init
(
SHA256_CTX
*
ctx
)
{
ctx
->
f
=
&
SHA256_VTAB
;
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
;
ctx
->
count
=
0
;
}
void
SHA256_update
(
SHA256_CTX
*
ctx
,
const
void
*
data
,
int
len
)
{
int
i
=
(
int
)
(
ctx
->
count
&
63
);
const
uint8_t
*
p
=
(
const
uint8_t
*
)
data
;
ctx
->
count
+=
len
;
while
(
len
--
)
{
ctx
->
buf
[
i
++
]
=
*
p
++
;
if
(
i
==
64
)
{
SHA256_Transform
(
ctx
);
i
=
0
;
}
}
}
const
uint8_t
*
SHA256_final
(
SHA256_CTX
*
ctx
)
{
uint8_t
*
p
=
ctx
->
buf
;
uint64_t
cnt
=
ctx
->
count
*
8
;
int
i
;
SHA256_update
(
ctx
,
(
uint8_t
*
)
"
\x80
"
,
1
);
while
((
ctx
->
count
&
63
)
!=
56
)
{
SHA256_update
(
ctx
,
(
uint8_t
*
)
"
\0
"
,
1
);
}
for
(
i
=
0
;
i
<
8
;
++
i
)
{
uint8_t
tmp
=
(
uint8_t
)
(
cnt
>>
((
7
-
i
)
*
8
));
SHA256_update
(
ctx
,
&
tmp
,
1
);
}
for
(
i
=
0
;
i
<
8
;
i
++
)
{
uint32_t
tmp
=
ctx
->
state
[
i
];
*
p
++
=
tmp
>>
24
;
*
p
++
=
tmp
>>
16
;
*
p
++
=
tmp
>>
8
;
*
p
++
=
tmp
>>
0
;
}
return
ctx
->
buf
;
}
/* Convenience function */
const
uint8_t
*
SHA256_hash
(
const
void
*
data
,
int
len
,
uint8_t
*
digest
)
{
SHA256_CTX
ctx
;
SHA256_init
(
&
ctx
);
SHA256_update
(
&
ctx
,
data
,
len
);
memcpy
(
digest
,
SHA256_final
(
&
ctx
),
SHA256_DIGEST_SIZE
);
return
digest
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment