Skip to content

Conversation

@aaronjamt
Copy link
Contributor

I copied the existing AES CMAC (cmac_calc.c/cmac_calc.h) and modified them to support 3DES. This will be used in a future PR for Seos emulation support, but I figured I'd open this PR now to reduce the amount of code added in that one.

@github-actions
Copy link

You are welcome to add an entry to the CHANGELOG.md as well

@aaronjamt
Copy link
Contributor Author

Just realized I somehow managed to commit the files in the wrong folder, fixed now.

armsrc/cmac_3des.c Dismissed
uint8_t L[8] = {0};

// Step 1: L = 3DES-ENC(0^64)
mbedtls_des3_crypt_ecb(ctx, L, L);

Check failure

Code scanning / CodeQL

Use of a broken or risky cryptographic algorithm High

This file makes use of a broken or weak cryptographic algorithm (specified by
call to mbedtls_des3_set2key_enc
).
This file makes use of a broken or weak cryptographic algorithm (specified by
call to mbedtls_des3_set3key_enc
).
This file makes use of a broken or weak cryptographic algorithm (specified by
call to mbedtls_des3_crypt_ecb
).
This file makes use of a broken or weak cryptographic algorithm (specified by
call to mbedtls_des3_crypt_ecb
).
This file makes use of a broken or weak cryptographic algorithm (specified by
call to mbedtls_des3_crypt_ecb
).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 😆
This is intentional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there's no way for me to suppress this error from my end, it has to be dismissed by a repository admin: https://docs.github.com/en/code-security/code-scanning/managing-code-scanning-alerts/resolving-code-scanning-alerts#dismissing-alerts

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just ignore it. We all know this project uses legacy crypto and broken crypto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, ok then. This won't cause the CI/CD to break after it's merged? I was only concerned because that test failed and I'm not sure if that'll cause other future PRs to also fail there.

pad[len] = 0x80;
for (size_t i = len + 1; i < 16; i++) {
pad[i] = 0x00;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove the loop with a simple call to memset before the memcpy call.

memset(pad, 0x00, len); memcpy(pad, lastb, len); pad[len] = 0x80; 
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be better to move this out into some more general utils.c or similar? This ISO7816 style padding is quite common at least in Seos, but I'm sure across the Proxmark codebase.

@iceman1001
Copy link
Collaborator

hm, hm, is the only different of this function the des_cmac() ? Might just merge it all into cmac_calc.c then.

@aaronjamt
Copy link
Contributor Author

hm, hm, is the only different of this function the des_cmac() ? Might just merge it all into cmac_calc.c then.

No, padding is the only one that's unchanged (and actually that should probably also be changed come to think of it). The methods in cmac_calc are all based on a 16-byte block whereas these are based on 8-byte (128 vs 64 bit). I could probably make them all work for both, and possibly even merge both CMACs into a single function that takes a "AES vs 3DES" flag, then make ulaes_cmac and 3des_cmac call it, if you'd like?

@iceman1001
Copy link
Collaborator

nay, if it's that much difference then we use this style.

I will merge and you can simplify the padding loop in both places with a new PR

@iceman1001 iceman1001 merged commit 8f6dd60 into RfidResearchGroup:master Dec 21, 2025
12 checks passed
@aaronjamt aaronjamt deleted the patch-3des-cmac branch December 21, 2025 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants