Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / apple / FindFamily / FindFamilyiOS / Crypto / PQCStubs.c
PQCStubs.c155 lines · 5.3 KiBRaw
| 1 | // PQCStubs.c — weak weak fallback stubs for Rust PQC native lib. |
| 2 | // |
| 3 | // Purpose: allows the iOS app to build and link even when libe2ee_pqc.a XCFramework |
| 4 | // is not present. Each function returns failure (0) / no-op, so PQC is reported as |
| 5 | // unavailable — no crash, no link error. There is no classic fallback: sharing simply |
| 6 | // does not work until the real library is linked. |
| 7 | // |
| 8 | // When the real Rust lib (src/main/rust) is built for iOS and added as |
| 9 | // e2ee_pqc.xcframework (static lib), its strong symbols override these weak ones |
| 10 | // at link time. The bundle format [4B kemLen][kemPub][dsaPub], sealed layout |
| 11 | // [4B encapLen][encap][aes] where aes = [12B iv][ct||tag], and KDF |
| 12 | // SHA256(BE32(1)||rawSS) stay identical to Office Android's e2ee-p2p implementation. |
| 13 | // |
| 14 | // Build XCFramework (from /Users/vayun/Documents/Modern-Apps/library/e2ee-p2p/src/main/rust): |
| 15 | // rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim |
| 16 | // cargo build --release --target aarch64-apple-ios |
| 17 | // cargo build --release --target x86_64-apple-ios |
| 18 | // cargo build --release --target aarch64-apple-ios-sim |
| 19 | // # lipo or xcodebuild -create-xcframework... |
| 20 | // # Place result at FindFamilyiOS/Frameworks/e2ee_pqc.xcframework and link it. |
| 21 | // |
| 22 | // No extra dependencies (dashmap not needed); the server relay stays opaque. |
| 23 | |
| 24 | #include <stddef.h> |
| 25 | #include <stdint.h> |
| 26 | |
| 27 | __attribute__((weak)) void pqc_free(uint8_t *ptr, size_t len) { |
| 28 | (void)ptr; (void)len; |
| 29 | } |
| 30 | |
| 31 | __attribute__((weak)) void pqc_secure_zero(uint8_t *ptr, size_t len) { |
| 32 | if (!ptr) return; |
| 33 | for (size_t i = 0; i < len; i++) ptr[i] = 0; |
| 34 | } |
| 35 | |
| 36 | __attribute__((weak)) int32_t pqc_kem_keygen( |
| 37 | uint8_t **pub_out, size_t *pub_len_out, |
| 38 | uint8_t **priv_out, size_t *priv_len_out) { |
| 39 | (void)pub_out; (void)pub_len_out; (void)priv_out; (void)priv_len_out; |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | __attribute__((weak)) int32_t pqc_dsa_keygen( |
| 44 | uint8_t **pub_out, size_t *pub_len_out, |
| 45 | uint8_t **priv_out, size_t *priv_len_out) { |
| 46 | (void)pub_out; (void)pub_len_out; (void)priv_out; (void)priv_len_out; |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | __attribute__((weak)) int32_t pqc_identity_keygen( |
| 51 | uint8_t **pub_bundle_out, size_t *pub_bundle_len_out, |
| 52 | uint8_t **priv_bundle_out, size_t *priv_bundle_len_out) { |
| 53 | (void)pub_bundle_out; (void)pub_bundle_len_out; |
| 54 | (void)priv_bundle_out; (void)priv_bundle_len_out; |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | __attribute__((weak)) int32_t pqc_link_keygen( |
| 59 | uint8_t **seed_out, size_t *seed_len_out, |
| 60 | uint8_t **pub_bundle_out, size_t *pub_bundle_len_out) { |
| 61 | (void)seed_out; (void)seed_len_out; |
| 62 | (void)pub_bundle_out; (void)pub_bundle_len_out; |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | __attribute__((weak)) int32_t pqc_link_pub_from_seed( |
| 67 | const uint8_t *seed, size_t seed_len, |
| 68 | uint8_t **pub_bundle_out, size_t *pub_bundle_len_out) { |
| 69 | (void)seed; (void)seed_len; |
| 70 | (void)pub_bundle_out; (void)pub_bundle_len_out; |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | __attribute__((weak)) int32_t pqc_kem_encaps( |
| 75 | const uint8_t *kem_pub, size_t kem_pub_len, |
| 76 | uint8_t **ct_out, size_t *ct_len_out, |
| 77 | uint8_t **ss_out, size_t *ss_len_out) { |
| 78 | (void)kem_pub; (void)kem_pub_len; |
| 79 | (void)ct_out; (void)ct_len_out; |
| 80 | (void)ss_out; (void)ss_len_out; |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | __attribute__((weak)) int32_t pqc_kem_decaps( |
| 85 | const uint8_t *kem_priv, size_t kem_priv_len, |
| 86 | const uint8_t *ct, size_t ct_len, |
| 87 | uint8_t **ss_out, size_t *ss_len_out) { |
| 88 | (void)kem_priv; (void)kem_priv_len; |
| 89 | (void)ct; (void)ct_len; |
| 90 | (void)ss_out; (void)ss_len_out; |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | __attribute__((weak)) int32_t pqc_dsa_sign( |
| 95 | const uint8_t *dsa_priv, size_t dsa_priv_len, |
| 96 | const uint8_t *msg, size_t msg_len, |
| 97 | uint8_t **sig_out, size_t *sig_len_out) { |
| 98 | (void)dsa_priv; (void)dsa_priv_len; |
| 99 | (void)msg; (void)msg_len; |
| 100 | (void)sig_out; (void)sig_len_out; |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | __attribute__((weak)) int32_t pqc_dsa_verify( |
| 105 | const uint8_t *dsa_pub, size_t dsa_pub_len, |
| 106 | const uint8_t *msg, size_t msg_len, |
| 107 | const uint8_t *sig, size_t sig_len) { |
| 108 | (void)dsa_pub; (void)dsa_pub_len; |
| 109 | (void)msg; (void)msg_len; |
| 110 | (void)sig; (void)sig_len; |
| 111 | return -1; |
| 112 | } |
| 113 | |
| 114 | __attribute__((weak)) int32_t pqc_security_code( |
| 115 | const uint8_t *my_bundle, size_t my_bundle_len, |
| 116 | const uint8_t *their_bundle, size_t their_bundle_len, |
| 117 | uint8_t *out, size_t out_len) { |
| 118 | (void)my_bundle; (void)my_bundle_len; |
| 119 | (void)their_bundle; (void)their_bundle_len; |
| 120 | (void)out; (void)out_len; |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | __attribute__((weak)) int32_t pqc_bundle_is_valid(const uint8_t *bundle, size_t bundle_len) { |
| 125 | (void)bundle; (void)bundle_len; |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | __attribute__((weak)) int32_t pqc_bundle_inspect( |
| 130 | const uint8_t *bundle, size_t bundle_len, |
| 131 | size_t *kem_pub_len_out, size_t *dsa_pub_len_out) { |
| 132 | (void)bundle; (void)bundle_len; |
| 133 | (void)kem_pub_len_out; (void)dsa_pub_len_out; |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | __attribute__((weak)) int32_t pqc_bundle_build( |
| 138 | const uint8_t *kem_pub, size_t kem_pub_len, |
| 139 | const uint8_t *dsa_pub, size_t dsa_pub_len, |
| 140 | uint8_t **out, size_t *out_len) { |
| 141 | (void)kem_pub; (void)kem_pub_len; |
| 142 | (void)dsa_pub; (void)dsa_pub_len; |
| 143 | (void)out; (void)out_len; |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | __attribute__((weak)) int32_t pqc_bundle_split( |
| 148 | const uint8_t *bundle, size_t bundle_len, |
| 149 | uint8_t **kem_pub_out, size_t *kem_pub_len_out, |
| 150 | uint8_t **dsa_pub_out, size_t *dsa_pub_len_out) { |
| 151 | (void)bundle; (void)bundle_len; |
| 152 | (void)kem_pub_out; (void)kem_pub_len_out; |
| 153 | (void)dsa_pub_out; (void)dsa_pub_len_out; |
| 154 | return 0; |
| 155 | } |