Crypto1 for MIFARE Classic.
More...
#include <mifare_classic_crypto1.hpp>
|
|
| Crypto1 () noexcept |
| | Default ctor (zero-initialized state)
|
| |
| | Crypto1 (const uint64_t key48) noexcept |
| | Construct with 48-bit key.
|
| |
| void | init (const uint64_t key48) noexcept |
| | Initialize with 48-bit key.
|
| |
| uint32_t | inject (uint32_t uid, uint32_t Nt, const bool encrypted=false) noexcept |
| | Inject UID and card nonce into the cipher state.
|
| |
| bool | step_with (const bool in, const bool enc=false) noexcept |
| | Step the cipher with one input bit.
|
| |
| uint8_t | step8 (const uint8_t in, const bool enc=false) noexcept |
| | Step the cipher with 8 input bits.
|
| |
| uint32_t | step32 (const uint32_t in, const bool enc=false) noexcept |
| | Step the cipher with 32 input bits.
|
| |
| uint8_t | encrypt (uint8_t buf[8], const uint32_t Nr, const uint32_t Ar) noexcept |
| | Encrypt reader nonce and authenticator response.
|
| |
| uint32_t | encrypt (uint8_t *out, const uint8_t *in, const uint8_t in_len) |
| | Encrypt a byte buffer.
|
| |
| bool | filter () const noexcept |
| | Crypto1 nonlinear filter.
|
| |
|
| static uint8_t | oddparity8 (uint8_t x) noexcept |
| | Calculate odd parity for one byte.
|
| |
| static bool | fa (bool a, bool b, bool c, bool d) noexcept |
| | Crypto1 filter helper A.
|
| |
| static bool | fb (bool a, bool b, bool c, bool d) noexcept |
| | Crypto1 filter helper B.
|
| |
| static bool | fc (bool a, bool b, bool c, bool d, bool e) noexcept |
| | Crypto1 filter helper C.
|
| |
Crypto1 for MIFARE Classic.
◆ Crypto1()
| m5::nfc::a::mifare::classic::Crypto1::Crypto1 |
( |
const uint64_t | key48 | ) |
|
|
inlineexplicitnoexcept |
Construct with 48-bit key.
- Parameters
-
| key48 | 48-bit MIFARE Classic key |
◆ encrypt() [1/2]
| uint32_t m5::nfc::a::mifare::classic::Crypto1::encrypt |
( |
uint8_t * | out, |
|
|
const uint8_t * | in, |
|
|
const uint8_t | in_len ) |
|
inline |
Encrypt a byte buffer.
- Parameters
-
| [out] | out | Output buffer |
| in | Input buffer |
| in_len | Input length, up to 32 bytes |
- Returns
- Packed parity bits for the encrypted bytes
◆ encrypt() [2/2]
| uint8_t m5::nfc::a::mifare::classic::Crypto1::encrypt |
( |
uint8_t | buf[8], |
|
|
const uint32_t | Nr, |
|
|
const uint32_t | Ar ) |
|
inlinenoexcept |
Encrypt reader nonce and authenticator response.
- Parameters
-
| [out] | buf | Output buffer at least 8 bytes |
| Nr | Reader nonce |
| Ar | Reader authenticator |
- Returns
- Packed parity bits for the encrypted bytes
◆ fa()
| static bool m5::nfc::a::mifare::classic::Crypto1::fa |
( |
bool | a, |
|
|
bool | b, |
|
|
bool | c, |
|
|
bool | d ) |
|
inlinestaticnoexcept |
Crypto1 filter helper A.
- Parameters
-
| a | Input bit a |
| b | Input bit b |
| c | Input bit c |
| d | Input bit d |
- Returns
- Filter helper result
◆ fb()
| static bool m5::nfc::a::mifare::classic::Crypto1::fb |
( |
bool | a, |
|
|
bool | b, |
|
|
bool | c, |
|
|
bool | d ) |
|
inlinestaticnoexcept |
Crypto1 filter helper B.
- Parameters
-
| a | Input bit a |
| b | Input bit b |
| c | Input bit c |
| d | Input bit d |
- Returns
- Filter helper result
◆ fc()
| static bool m5::nfc::a::mifare::classic::Crypto1::fc |
( |
bool | a, |
|
|
bool | b, |
|
|
bool | c, |
|
|
bool | d, |
|
|
bool | e ) |
|
inlinestaticnoexcept |
Crypto1 filter helper C.
- Parameters
-
| a | Input bit a |
| b | Input bit b |
| c | Input bit c |
| d | Input bit d |
| e | Input bit e |
- Returns
- Filter helper result
◆ filter()
| bool m5::nfc::a::mifare::classic::Crypto1::filter |
( |
| ) |
const |
|
inlinenoexcept |
Crypto1 nonlinear filter.
- Returns
- Current keystream bit
◆ init()
| void m5::nfc::a::mifare::classic::Crypto1::init |
( |
const uint64_t | key48 | ) |
|
|
inlinenoexcept |
Initialize with 48-bit key.
- Parameters
-
| key48 | 48-bit MIFARE Classic key |
◆ inject()
| uint32_t m5::nfc::a::mifare::classic::Crypto1::inject |
( |
uint32_t | uid, |
|
|
uint32_t | Nt, |
|
|
const bool | encrypted = false ) |
|
inlinenoexcept |
Inject UID and card nonce into the cipher state.
- Parameters
-
| uid | 32-bit UID value |
| Nt | Card nonce |
| encrypted | True if the injected bits are encrypted |
- Returns
- Generated 32-bit keystream value
◆ oddparity8()
| static uint8_t m5::nfc::a::mifare::classic::Crypto1::oddparity8 |
( |
uint8_t | x | ) |
|
|
inlinestaticnoexcept |
Calculate odd parity for one byte.
- Parameters
-
- Returns
- Parity bit that makes the byte odd parity
◆ step32()
| uint32_t m5::nfc::a::mifare::classic::Crypto1::step32 |
( |
const uint32_t | in, |
|
|
const bool | enc = false ) |
|
inlinenoexcept |
Step the cipher with 32 input bits.
- Parameters
-
| in | Input 32-bit value |
| enc | True if the input value is encrypted |
- Returns
- Generated 32-bit keystream value
◆ step8()
| uint8_t m5::nfc::a::mifare::classic::Crypto1::step8 |
( |
const uint8_t | in, |
|
|
const bool | enc = false ) |
|
inlinenoexcept |
Step the cipher with 8 input bits.
- Parameters
-
| in | Input byte |
| enc | True if the input byte is encrypted |
- Returns
- Generated 8-bit keystream value
◆ step_with()
| bool m5::nfc::a::mifare::classic::Crypto1::step_with |
( |
const bool | in, |
|
|
const bool | enc = false ) |
|
inlinenoexcept |
Step the cipher with one input bit.
- Parameters
-
| in | Input bit |
| enc | True if the input bit is encrypted |
- Returns
- Generated keystream bit before the state update