-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WPAPSK CPU formats: Remove dependency on OpenSSL for 802.11w support #5614
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* This code implements the CMAC (Cipher-based Message Authentication) | ||
* algorithm described in FIPS SP800-38B using the AES-128 cipher. | ||
* | ||
* Copyright (c) 2017, magnum. | ||
* Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr> | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
#ifndef JTR_CMAC_H | ||
#define JTR_CMAC_H | ||
|
||
#include <stdint.h> | ||
|
||
#include "aes.h" | ||
|
||
#define AES_CMAC_KEY_LENGTH 16 | ||
#define AES_CMAC_DIGEST_LENGTH 16 | ||
|
||
typedef struct _AES_CMAC_CTX { | ||
AES_KEY aesctx; | ||
uint8_t X[16]; | ||
uint8_t M_last[16]; | ||
uint32_t M_n; | ||
} AES_CMAC_CTX; | ||
|
||
extern void AES_CMAC_Init(AES_CMAC_CTX *ctx); | ||
extern void AES_CMAC_SetKey(AES_CMAC_CTX *ctx, const uint8_t *key); | ||
extern void AES_CMAC_Update(AES_CMAC_CTX *ctx, const uint8_t *data, uint32_t len); | ||
extern void AES_CMAC_Final(uint8_t *digest, AES_CMAC_CTX *ctx); | ||
|
||
#endif /* JTR_CMAC_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* This code implements the CMAC (Cipher-based Message Authentication) | ||
* algorithm described in FIPS SP800-38B using the AES-128 cipher. | ||
* | ||
* Copyright (c) 2017, magnum. | ||
* Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr> | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
#include "cmac.h" | ||
#include "common.h" | ||
|
||
#define LSHIFT(v, r) do { \ | ||
uint32_t i; \ | ||
for (i = 0; i < 15; i++) \ | ||
(r)[i] = (v)[i] << 1 | (v)[i + 1] >> 7; \ | ||
(r)[15] = (v)[15] << 1; \ | ||
} while (0) | ||
|
||
#define XOR(v, r) do { \ | ||
uint32_t i; \ | ||
for (i = 0; i < 16; i++) \ | ||
(r)[i] ^= (v)[i]; \ | ||
} while (0) | ||
|
||
void AES_CMAC_Init(AES_CMAC_CTX *ctx) | ||
{ | ||
uint32_t i; | ||
|
||
for (i = 0; i < 16; i++) | ||
ctx->X[i] = 0; | ||
ctx->M_n = 0; | ||
} | ||
|
||
void AES_CMAC_SetKey(AES_CMAC_CTX *ctx, const uint8_t *key) | ||
{ | ||
AES_set_encrypt_key(key, 128, &ctx->aesctx); | ||
} | ||
|
||
void AES_CMAC_Update(AES_CMAC_CTX *ctx, const uint8_t *data, uint32_t len) | ||
{ | ||
uint32_t i; | ||
|
||
if (ctx->M_n > 0) { | ||
uint32_t mlen = MIN(16 - ctx->M_n, len); | ||
|
||
for (i = 0; i < mlen; i++) | ||
ctx->M_last[ctx->M_n + i] = data[i]; | ||
ctx->M_n += mlen; | ||
if (ctx->M_n < 16 || len == mlen) | ||
return; | ||
XOR(ctx->M_last, ctx->X); | ||
AES_encrypt(ctx->X, ctx->X, &ctx->aesctx); | ||
data += mlen; | ||
len -= mlen; | ||
} | ||
while (len > 16) { /* not last block */ | ||
XOR(data, ctx->X); | ||
AES_encrypt(ctx->X, ctx->X, &ctx->aesctx); | ||
data += 16; | ||
len -= 16; | ||
} | ||
/* potential last block, save it */ | ||
for (i = 0; i < len; i++) | ||
ctx->M_last[i] = data[i]; | ||
ctx->M_n = len; | ||
} | ||
|
||
void AES_CMAC_Final(uint8_t *digest, AES_CMAC_CTX *ctx) | ||
{ | ||
uint8_t K[16] = { 0 }; | ||
|
||
/* generate subkey K1 */ | ||
AES_encrypt(K, K, &ctx->aesctx); | ||
|
||
if (K[0] & 0x80) { | ||
LSHIFT(K, K); | ||
K[15] ^= 0x87; | ||
} else | ||
LSHIFT(K, K); | ||
|
||
if (ctx->M_n == 16) { | ||
/* last block was a complete block */ | ||
XOR(K, ctx->M_last); | ||
} else { | ||
/* generate subkey K2 */ | ||
if (K[0] & 0x80) { | ||
LSHIFT(K, K); | ||
K[15] ^= 0x87; | ||
} else | ||
LSHIFT(K, K); | ||
|
||
/* padding(M_last) */ | ||
ctx->M_last[ctx->M_n] = 0x80; | ||
while (++ctx->M_n < 16) | ||
ctx->M_last[ctx->M_n] = 0; | ||
|
||
XOR(K, ctx->M_last); | ||
} | ||
XOR(ctx->M_last, ctx->X); | ||
AES_encrypt(ctx->X, digest, &ctx->aesctx); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do we use from
common.h
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the MIN() macro.