diff options
author | Joseph Jang <josephjang@google.com> | 2022-09-08 12:10:55 +0000 |
---|---|---|
committer | Joseph Jang <josephjang@google.com> | 2022-09-08 12:20:08 +0000 |
commit | 0907ea0f7ee9db0f920024a99f45c939bc26d49f (patch) | |
tree | e10aad088ee07986278c639227b150cc85b1e8ba /identity | |
parent | 6c5ab6a0435e034e11124bdb12cf50a82120ba33 (diff) | |
download | security-0907ea0f7ee9db0f920024a99f45c939bc26d49f.tar.gz |
identity: Fix incorrect encoding P256 public key
Bug: 240359297
Change-Id: I8799f41765fe1acae2e11739806d4aedeb93976c
Diffstat (limited to 'identity')
-rw-r--r-- | identity/util/src/java/com/android/security/identity/internal/Util.java | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/identity/util/src/java/com/android/security/identity/internal/Util.java b/identity/util/src/java/com/android/security/identity/internal/Util.java index de7369a5..ee12cd07 100644 --- a/identity/util/src/java/com/android/security/identity/internal/Util.java +++ b/identity/util/src/java/com/android/security/identity/internal/Util.java @@ -1150,22 +1150,24 @@ Certificate: if (xBytes.length > 32) { throw new RuntimeException("xBytes is " + xBytes.length + " which is unexpected"); } - for (int n = 0; n < 32 - xBytes.length; n++) { + int numLeadingZeroBytes = 32 - xBytes.length; + for (int n = 0; n < numLeadingZeroBytes; n++) { ret[n] = 0x00; } - for (int n = 32 - xBytes.length; n < xBytes.length; n++) { - ret[n] = xBytes[n]; + for (int n = 0; n < xBytes.length; n++) { + ret[numLeadingZeroBytes + n] = xBytes[n]; } byte[] yBytes = stripLeadingZeroes(w.getAffineY().toByteArray()); if (yBytes.length > 32) { throw new RuntimeException("yBytes is " + yBytes.length + " which is unexpected"); } - for (int n = 0; n < 32 - yBytes.length; n++) { + numLeadingZeroBytes = 32 - yBytes.length; + for (int n = 0; n < numLeadingZeroBytes; n++) { ret[32 + n] = 0x00; } - for (int n = 32 - yBytes.length; n < yBytes.length; n++) { - ret[32 + n] = yBytes[n]; + for (int n = 0; n < yBytes.length; n++) { + ret[32 + numLeadingZeroBytes + n] = yBytes[n]; } return ret; |