forked from JoeMatt/AltSign
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathnative_bridge_corecrypto.cpp
More file actions
124 lines (104 loc) · 2.72 KB
/
Copy pathnative_bridge_corecrypto.cpp
File metadata and controls
124 lines (104 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// native_bridge_corecrypto.cpp
// AltSign
//
#include "native_bridge_corecrypto.h"
#include <stdlib.h>
#include <string.h>
#define CORECRYPTO_USE_TRANSPARENT_UNION 1
#define CC_INTERNAL_SDK 1
#define CC_USE_L4 0
extern "C" {
#include <corecrypto/ccdigest.h>
#include <corecrypto/ccsha2.h>
#include <corecrypto/ccsrp.h>
#include <corecrypto/ccsrp_gp.h>
#include <corecrypto/ccrng.h>
// ============================================================
// MARK: - SRP
// ============================================================
const void* native_bridge_ccsrp_gp_rfc5054_2048(void)
{
return ccsrp_gp_rfc5054_2048();
}
const void* native_bridge_ccsha256_di(void)
{
return ccsha256_di();
}
ccsrp_context native_bridge_ccsrp_client_new(void)
{
ccsrp_const_gp_t gp = ccsrp_gp_rfc5054_2048();
const struct ccdigest_info *di = ccsha256_di();
size_t size = 4096; // conservative upper bound for the SRP workspace
ccsrp_ctx_t ctx = (ccsrp_ctx_t)malloc(size);
if (!ctx) return nullptr;
ccsrp_ctx_init(ctx, di, gp);
ccsrp_client_set_noUsernameInX(ctx, true); // Apple GSA omits username from x derivation
return ctx;
}
void native_bridge_ccsrp_client_free(ccsrp_context ctx)
{
if (ctx) free(ctx);
}
size_t native_bridge_ccsrp_exchange_size(ccsrp_context ctx)
{
return ccsrp_exchange_size((ccsrp_ctx_t)ctx);
}
int native_bridge_ccsrp_client_start_authentication(
ccsrp_context ctx,
void *A_bytes,
void *rng)
{
struct ccrng_state *rng_state = (struct ccrng_state*)rng;
if (!rng_state) {
// Use the system default RNG when no explicit RNG is provided
int err = 0;
rng_state = ccrng(&err);
}
return ccsrp_client_start_authentication(
(ccsrp_ctx_t)ctx,
rng_state,
A_bytes
);
}
int native_bridge_ccsrp_client_process_challenge(
ccsrp_context ctx,
const void *salt,
size_t salt_len,
const void *B,
size_t B_len,
const char *username,
const void *password,
size_t password_len,
void *M_bytes
){
return ccsrp_client_process_challenge(
(ccsrp_ctx_t)ctx,
username,
password_len,
password,
salt_len,
salt,
B,
M_bytes
);
}
int native_bridge_ccsrp_client_verify_session(
ccsrp_context ctx,
const void *M2
){
return ccsrp_client_verify_session(
(ccsrp_ctx_t)ctx,
(const uint8_t*)M2
);
}
const void* native_bridge_ccsrp_get_session_key(ccsrp_context ctx)
{
size_t len = 0;
return ccsrp_get_session_key((ccsrp_ctx_t)ctx, &len);
}
size_t native_bridge_ccsrp_get_session_key_length(ccsrp_context ctx)
{
return ccsrp_get_session_key_length((ccsrp_ctx_t)ctx);
}
} // extern "C"