Skip to content

Commit 45312d8

Browse files
author
Xia Ning
committed
add gcm/aes encryption example
only init cipher context during register packet observer
1 parent 4d9c008 commit 45312d8

114 files changed

Lines changed: 32091 additions & 126 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Android/APIExample/lib-stream-encrypt/CMakeLists.txt

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,37 @@
55

66
cmake_minimum_required(VERSION 3.4.1)
77

8-
add_library(apm-plugin-packet-processing SHARED
9-
./src/main/cpp/packet_processing_plugin_jni.cpp
8+
include_directories(src/main/cpp/include)
9+
10+
add_library(
11+
apm-plugin-packet-processing
12+
SHARED
13+
src/main/cpp/packet_processing_plugin_jni.cpp
1014
)
1115

12-
include_directories(./src/main/cpp/include)
16+
add_library(openssl-crypto
17+
STATIC
18+
IMPORTED)
19+
20+
set_target_properties(
21+
openssl-crypto
22+
PROPERTIES IMPORTED_LOCATION
23+
"${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libcrypto.a")
24+
25+
add_library(openssl-ssl
26+
STATIC
27+
IMPORTED)
28+
29+
set_target_properties(
30+
openssl-ssl
31+
PROPERTIES IMPORTED_LOCATION
32+
"${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libssl.a")
1333

1434
find_library(log-lib log)
1535

16-
target_link_libraries(apm-plugin-packet-processing ${log-lib})
36+
target_link_libraries(
37+
apm-plugin-packet-processing
38+
openssl-crypto
39+
openssl-ssl
40+
${log-lib}
41+
)

Android/APIExample/lib-stream-encrypt/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ android {
2727
}
2828
}
2929

30+
// sourceSets {
31+
// main {
32+
// jniLibs.srcDirs = ['src/main/jniLibs']
33+
// }
34+
// }
3035
}
3136

3237
dependencies {
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
3+
*
4+
* Licensed under the OpenSSL license (the "License"). You may not use
5+
* this file except in compliance with the License. You can obtain a copy
6+
* in the file LICENSE in the source distribution or at
7+
* https://www.openssl.org/source/license.html
8+
*/
9+
10+
#ifndef HEADER_AES_H
11+
# define HEADER_AES_H
12+
13+
# include <openssl/opensslconf.h>
14+
15+
# include <stddef.h>
16+
# ifdef __cplusplus
17+
extern "C" {
18+
# endif
19+
20+
# define AES_ENCRYPT 1
21+
# define AES_DECRYPT 0
22+
23+
/*
24+
* Because array size can't be a const in C, the following two are macros.
25+
* Both sizes are in bytes.
26+
*/
27+
# define AES_MAXNR 14
28+
# define AES_BLOCK_SIZE 16
29+
30+
/* This should be a hidden type, but EVP requires that the size be known */
31+
struct aes_key_st {
32+
# ifdef AES_LONG
33+
unsigned long rd_key[4 * (AES_MAXNR + 1)];
34+
# else
35+
unsigned int rd_key[4 * (AES_MAXNR + 1)];
36+
# endif
37+
int rounds;
38+
};
39+
typedef struct aes_key_st AES_KEY;
40+
41+
const char *AES_options(void);
42+
43+
int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
44+
AES_KEY *key);
45+
int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
46+
AES_KEY *key);
47+
48+
void AES_encrypt(const unsigned char *in, unsigned char *out,
49+
const AES_KEY *key);
50+
void AES_decrypt(const unsigned char *in, unsigned char *out,
51+
const AES_KEY *key);
52+
53+
void AES_ecb_encrypt(const unsigned char *in, unsigned char *out,
54+
const AES_KEY *key, const int enc);
55+
void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
56+
size_t length, const AES_KEY *key,
57+
unsigned char *ivec, const int enc);
58+
void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
59+
size_t length, const AES_KEY *key,
60+
unsigned char *ivec, int *num, const int enc);
61+
void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out,
62+
size_t length, const AES_KEY *key,
63+
unsigned char *ivec, int *num, const int enc);
64+
void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out,
65+
size_t length, const AES_KEY *key,
66+
unsigned char *ivec, int *num, const int enc);
67+
void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,
68+
size_t length, const AES_KEY *key,
69+
unsigned char *ivec, int *num);
70+
/* NB: the IV is _two_ blocks long */
71+
void AES_ige_encrypt(const unsigned char *in, unsigned char *out,
72+
size_t length, const AES_KEY *key,
73+
unsigned char *ivec, const int enc);
74+
/* NB: the IV is _four_ blocks long */
75+
void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out,
76+
size_t length, const AES_KEY *key,
77+
const AES_KEY *key2, const unsigned char *ivec,
78+
const int enc);
79+
80+
int AES_wrap_key(AES_KEY *key, const unsigned char *iv,
81+
unsigned char *out,
82+
const unsigned char *in, unsigned int inlen);
83+
int AES_unwrap_key(AES_KEY *key, const unsigned char *iv,
84+
unsigned char *out,
85+
const unsigned char *in, unsigned int inlen);
86+
87+
88+
# ifdef __cplusplus
89+
}
90+
# endif
91+
92+
#endif

0 commit comments

Comments
 (0)