#include <stdio.h>
#include <ctype.h>
#include <nettle/pbkdf2.h>
#include <nettle/aes.h>
#include <nettle/eax.h>
#include <unistd.h>
#define PassLength 8
#define SaltLength 64
#define NonceLength 16
#define Iterations 1310720
int main(){
const uint8_t salt[SaltLength] = {
0xf9, 0xa4, 0xe3, 0xf1, 0x85, 0x10, 0xfb, 0x5c, 0x49, 0x7c, 0xb2, 0xfd,
0x37, 0xdc, 0x8e, 0x4a, 0xaf, 0x65, 0x98, 0xbc, 0xf0, 0x24, 0xd2, 0x54,
0x87, 0x93, 0x7e, 0x40, 0xca, 0x51, 0xdf, 0x8c, 0xab, 0xa3, 0xe6, 0xca,
0x62, 0xa7, 0xdd, 0xda, 0x79, 0x37, 0x18, 0x21, 0x87, 0xe0, 0x4d, 0x2c,
0xd8, 0xe1, 0xef, 0xac, 0x19, 0x3a, 0x69, 0x98, 0x42, 0x92, 0x23, 0x01,
0xad, 0xe9, 0x47, 0x77
};
const uint8_t nonce[NonceLength] = {
0x03, 0xfe, 0x52, 0x82, 0xd1, 0x5d, 0x2a, 0x31, 0xf2, 0x09, 0x84, 0x69,
0x5b, 0x68, 0x31, 0xa1
};
const uint8_t data[20] = {
0xd9, 0x0d, 0x6f, 0xc3, 0x39, 0x39, 0x36, 0x80, 0x61, 0x2f, 0x6b, 0xed,
0x0e, 0x67, 0x94, 0xc0, 0x18, 0x3e, 0x75, 0xbb
};
const uint8_t digest[EAX_DIGEST_SIZE] = {
0x36, 0x3c, 0x51, 0x82, 0x4e, 0x3b, 0xce, 0x36, 0x9c, 0xac, 0x72, 0x44,
0x09, 0xbb, 0x31, 0x84
};
uint8_t pass[PassLength] = {0x31, 0x30, 0x30, 0x30, 0x38, 0x33, 0x33, 0x38};
uint8_t key[AES256_KEY_SIZE];
uint8_t result[20];
uint8_t input_digest[EAX_DIGEST_SIZE];
int flag = 0;
struct aes256_ctx aes_ctx;
struct eax_key eax_key;
struct eax_ctx eax_ctx;
printf("Enter pass: ");
if(fread(pass, PassLength, 1, stdin) != 1) flag = 1;
for(int i = 0; i < PassLength; ++i) if(!isdigit(pass[i])) flag = 1;
pbkdf2_hmac_sha512(PassLength, pass, Iterations, SaltLength, salt, AES256_KEY_SIZE, key);
aes256_set_encrypt_key(&aes_ctx, key);
eax_set_key(&eax_key, &aes_ctx, aes256_encrypt);
eax_set_nonce(&eax_ctx, &eax_key, &aes_ctx, aes256_encrypt, NonceLength, nonce);
eax_decrypt(&eax_ctx, &eax_key, &aes_ctx, aes256_encrypt, 20, result, data);
eax_digest(&eax_ctx, &eax_key, &aes_ctx, aes256_encrypt, EAX_DIGEST_SIZE, input_digest);
for(size_t i = 0; i < EAX_DIGEST_SIZE; ++i) flag |= digest[i] ^ input_digest[i];
if(flag){
sleep(3);
printf("Pass failed.\n");
}else{
printf("Pass succeed.\n");
printf("%s\n", result);
}
return 0;
}
设计思想上是希望只能通过枚举尝试出来才能得到密码的,实际上做的怎么样就不好说了