service/ps: Implement PS:EncryptDecryptAES

This commit is contained in:
zhupengfei 2019-04-15 22:56:55 +08:00
parent 14730ed560
commit b34847d59e
No known key found for this signature in database
GPG key ID: DD129E108BD09378
6 changed files with 145 additions and 2 deletions

View file

@ -36,6 +36,20 @@ AESKey Add128(const AESKey& a, const AESKey& b) {
return out;
}
AESKey Add128(const AESKey& a, u64 b) {
AESKey out = a;
u32 carry = 0;
u32 sum = 0;
for (int i = 15; i >= 8; i--) {
sum = a[i] + static_cast<u8>((b >> ((15 - i) * 8)) & 0xff) + carry;
carry = sum >> 8;
out[i] = static_cast<u8>(sum & 0xff);
}
return out;
}
AESKey Xor128(const AESKey& a, const AESKey& b) {
AESKey out;
std::transform(a.cbegin(), a.cend(), b.cbegin(), out.begin(), std::bit_xor<>());

View file

@ -10,6 +10,7 @@
namespace HW::AES {
AESKey Lrot128(const AESKey& in, u32 rot);
AESKey Add128(const AESKey& a, const AESKey& b);
AESKey Add128(const AESKey& a, u64 b);
AESKey Xor128(const AESKey& a, const AESKey& b);
} // namespace HW::AES