003 File Manager
Current Path:
/usr/src/contrib/wpa/src/crypto
usr
/
src
/
contrib
/
wpa
/
src
/
crypto
/
📁
..
📄
aes-cbc.c
(1.93 KB)
📄
aes-ccm.c
(4.92 KB)
📄
aes-ctr.c
(1.64 KB)
📄
aes-eax.c
(3.24 KB)
📄
aes-encblock.c
(704 B)
📄
aes-gcm.c
(6.47 KB)
📄
aes-internal-dec.c
(3.64 KB)
📄
aes-internal-enc.c
(2.66 KB)
📄
aes-internal.c
(41.23 KB)
📄
aes-omac1.c
(4.46 KB)
📄
aes-siv.c
(4.06 KB)
📄
aes-unwrap.c
(1.78 KB)
📄
aes-wrap.c
(1.62 KB)
📄
aes.h
(548 B)
📄
aes_i.h
(4.16 KB)
📄
aes_siv.h
(565 B)
📄
aes_wrap.h
(2.91 KB)
📄
crypto.h
(28.61 KB)
📄
crypto_gnutls.c
(11.42 KB)
📄
crypto_internal-cipher.c
(5.08 KB)
📄
crypto_internal-modexp.c
(2.95 KB)
📄
crypto_internal-rsa.c
(2.81 KB)
📄
crypto_internal.c
(6.84 KB)
📄
crypto_libtomcrypt.c
(15.07 KB)
📄
crypto_linux.c
(21.77 KB)
📄
crypto_module_tests.c
(61.19 KB)
📄
crypto_nettle.c
(9.7 KB)
📄
crypto_none.c
(461 B)
📄
crypto_openssl.c
(44.34 KB)
📄
crypto_wolfssl.c
(33.91 KB)
📄
des-internal.c
(14.83 KB)
📄
des_i.h
(709 B)
📄
dh_group5.c
(806 B)
📄
dh_group5.h
(556 B)
📄
dh_groups.c
(54.26 KB)
📄
dh_groups.h
(692 B)
📄
fips_prf_internal.c
(1.37 KB)
📄
fips_prf_openssl.c
(2.05 KB)
📄
fips_prf_wolfssl.c
(1.75 KB)
📄
md4-internal.c
(7.91 KB)
📄
md5-internal.c
(8.79 KB)
📄
md5.c
(2.64 KB)
📄
md5.h
(505 B)
📄
md5_i.h
(516 B)
📄
milenage.c
(9.5 KB)
📄
milenage.h
(1019 B)
📄
ms_funcs.c
(16.16 KB)
📄
ms_funcs.h
(2.41 KB)
📄
random.c
(11.66 KB)
📄
random.h
(855 B)
📄
rc4.c
(1009 B)
📄
sha1-internal.c
(8.93 KB)
📄
sha1-pbkdf2.c
(2.34 KB)
📄
sha1-prf.c
(1.58 KB)
📄
sha1-tlsprf.c
(2.69 KB)
📄
sha1-tprf.c
(1.75 KB)
📄
sha1.c
(2.69 KB)
📄
sha1.h
(1.03 KB)
📄
sha1_i.h
(590 B)
📄
sha256-internal.c
(6 KB)
📄
sha256-kdf.c
(2.08 KB)
📄
sha256-prf.c
(2.84 KB)
📄
sha256-tlsprf.c
(1.81 KB)
📄
sha256.c
(2.64 KB)
📄
sha256.h
(1.07 KB)
📄
sha256_i.h
(584 B)
📄
sha384-internal.c
(2.17 KB)
📄
sha384-kdf.c
(2.08 KB)
📄
sha384-prf.c
(2.85 KB)
📄
sha384.c
(2.63 KB)
📄
sha384.h
(949 B)
📄
sha384_i.h
(573 B)
📄
sha512-internal.c
(7.71 KB)
📄
sha512-kdf.c
(2.08 KB)
📄
sha512-prf.c
(2.85 KB)
📄
sha512.c
(2.63 KB)
📄
sha512.h
(949 B)
📄
sha512_i.h
(591 B)
📄
tls.h
(23.71 KB)
📄
tls_gnutls.c
(44.97 KB)
📄
tls_internal.c
(18.93 KB)
📄
tls_none.c
(3.9 KB)
📄
tls_openssl.c
(137.99 KB)
📄
tls_openssl.h
(477 B)
📄
tls_openssl_ocsp.c
(20.52 KB)
📄
tls_wolfssl.c
(51.88 KB)
Editing: aes-ccm.c
/* * Counter with CBC-MAC (CCM) with AES * * Copyright (c) 2010-2012, Jouni Malinen <j@w1.fi> * * This software may be distributed under the terms of the BSD license. * See README for more details. */ #include "includes.h" #include "common.h" #include "aes.h" #include "aes_wrap.h" static void xor_aes_block(u8 *dst, const u8 *src) { u32 *d = (u32 *) dst; u32 *s = (u32 *) src; *d++ ^= *s++; *d++ ^= *s++; *d++ ^= *s++; *d++ ^= *s++; } static void aes_ccm_auth_start(void *aes, size_t M, size_t L, const u8 *nonce, const u8 *aad, size_t aad_len, size_t plain_len, u8 *x) { u8 aad_buf[2 * AES_BLOCK_SIZE]; u8 b[AES_BLOCK_SIZE]; /* Authentication */ /* B_0: Flags | Nonce N | l(m) */ b[0] = aad_len ? 0x40 : 0 /* Adata */; b[0] |= (((M - 2) / 2) /* M' */ << 3); b[0] |= (L - 1) /* L' */; os_memcpy(&b[1], nonce, 15 - L); WPA_PUT_BE16(&b[AES_BLOCK_SIZE - L], plain_len); wpa_hexdump_key(MSG_EXCESSIVE, "CCM B_0", b, AES_BLOCK_SIZE); aes_encrypt(aes, b, x); /* X_1 = E(K, B_0) */ if (!aad_len) return; WPA_PUT_BE16(aad_buf, aad_len); os_memcpy(aad_buf + 2, aad, aad_len); os_memset(aad_buf + 2 + aad_len, 0, sizeof(aad_buf) - 2 - aad_len); xor_aes_block(aad_buf, x); aes_encrypt(aes, aad_buf, x); /* X_2 = E(K, X_1 XOR B_1) */ if (aad_len > AES_BLOCK_SIZE - 2) { xor_aes_block(&aad_buf[AES_BLOCK_SIZE], x); /* X_3 = E(K, X_2 XOR B_2) */ aes_encrypt(aes, &aad_buf[AES_BLOCK_SIZE], x); } } static void aes_ccm_auth(void *aes, const u8 *data, size_t len, u8 *x) { size_t last = len % AES_BLOCK_SIZE; size_t i; for (i = 0; i < len / AES_BLOCK_SIZE; i++) { /* X_i+1 = E(K, X_i XOR B_i) */ xor_aes_block(x, data); data += AES_BLOCK_SIZE; aes_encrypt(aes, x, x); } if (last) { /* XOR zero-padded last block */ for (i = 0; i < last; i++) x[i] ^= *data++; aes_encrypt(aes, x, x); } } static void aes_ccm_encr_start(size_t L, const u8 *nonce, u8 *a) { /* A_i = Flags | Nonce N | Counter i */ a[0] = L - 1; /* Flags = L' */ os_memcpy(&a[1], nonce, 15 - L); } static void aes_ccm_encr(void *aes, size_t L, const u8 *in, size_t len, u8 *out, u8 *a) { size_t last = len % AES_BLOCK_SIZE; size_t i; /* crypt = msg XOR (S_1 | S_2 | ... | S_n) */ for (i = 1; i <= len / AES_BLOCK_SIZE; i++) { WPA_PUT_BE16(&a[AES_BLOCK_SIZE - 2], i); /* S_i = E(K, A_i) */ aes_encrypt(aes, a, out); xor_aes_block(out, in); out += AES_BLOCK_SIZE; in += AES_BLOCK_SIZE; } if (last) { WPA_PUT_BE16(&a[AES_BLOCK_SIZE - 2], i); aes_encrypt(aes, a, out); /* XOR zero-padded last block */ for (i = 0; i < last; i++) *out++ ^= *in++; } } static void aes_ccm_encr_auth(void *aes, size_t M, u8 *x, u8 *a, u8 *auth) { size_t i; u8 tmp[AES_BLOCK_SIZE]; wpa_hexdump_key(MSG_EXCESSIVE, "CCM T", x, M); /* U = T XOR S_0; S_0 = E(K, A_0) */ WPA_PUT_BE16(&a[AES_BLOCK_SIZE - 2], 0); aes_encrypt(aes, a, tmp); for (i = 0; i < M; i++) auth[i] = x[i] ^ tmp[i]; wpa_hexdump_key(MSG_EXCESSIVE, "CCM U", auth, M); } static void aes_ccm_decr_auth(void *aes, size_t M, u8 *a, const u8 *auth, u8 *t) { size_t i; u8 tmp[AES_BLOCK_SIZE]; wpa_hexdump_key(MSG_EXCESSIVE, "CCM U", auth, M); /* U = T XOR S_0; S_0 = E(K, A_0) */ WPA_PUT_BE16(&a[AES_BLOCK_SIZE - 2], 0); aes_encrypt(aes, a, tmp); for (i = 0; i < M; i++) t[i] = auth[i] ^ tmp[i]; wpa_hexdump_key(MSG_EXCESSIVE, "CCM T", t, M); } /* AES-CCM with fixed L=2 and aad_len <= 30 assumption */ int aes_ccm_ae(const u8 *key, size_t key_len, const u8 *nonce, size_t M, const u8 *plain, size_t plain_len, const u8 *aad, size_t aad_len, u8 *crypt, u8 *auth) { const size_t L = 2; void *aes; u8 x[AES_BLOCK_SIZE], a[AES_BLOCK_SIZE]; if (aad_len > 30 || M > AES_BLOCK_SIZE) return -1; aes = aes_encrypt_init(key, key_len); if (aes == NULL) return -1; aes_ccm_auth_start(aes, M, L, nonce, aad, aad_len, plain_len, x); aes_ccm_auth(aes, plain, plain_len, x); /* Encryption */ aes_ccm_encr_start(L, nonce, a); aes_ccm_encr(aes, L, plain, plain_len, crypt, a); aes_ccm_encr_auth(aes, M, x, a, auth); aes_encrypt_deinit(aes); return 0; } /* AES-CCM with fixed L=2 and aad_len <= 30 assumption */ int aes_ccm_ad(const u8 *key, size_t key_len, const u8 *nonce, size_t M, const u8 *crypt, size_t crypt_len, const u8 *aad, size_t aad_len, const u8 *auth, u8 *plain) { const size_t L = 2; void *aes; u8 x[AES_BLOCK_SIZE], a[AES_BLOCK_SIZE]; u8 t[AES_BLOCK_SIZE]; if (aad_len > 30 || M > AES_BLOCK_SIZE) return -1; aes = aes_encrypt_init(key, key_len); if (aes == NULL) return -1; /* Decryption */ aes_ccm_encr_start(L, nonce, a); aes_ccm_decr_auth(aes, M, a, auth, t); /* plaintext = msg XOR (S_1 | S_2 | ... | S_n) */ aes_ccm_encr(aes, L, crypt, crypt_len, plain, a); aes_ccm_auth_start(aes, M, L, nonce, aad, aad_len, crypt_len, x); aes_ccm_auth(aes, plain, crypt_len, x); aes_encrypt_deinit(aes); if (os_memcmp_const(x, t, M) != 0) { wpa_printf(MSG_EXCESSIVE, "CCM: Auth mismatch"); return -1; } return 0; }
Upload File
Create Folder