Skip to content

Commit

Permalink
Fix incrementNonce() to work when multiple bytes need to increment.
Browse files Browse the repository at this point in the history
  • Loading branch information
causalnet committed Jan 15, 2023
1 parent 750da2e commit 4f6fe4a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/org/keepassxc/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,13 @@ private byte[] ramdomGenerateNonce() {
private byte[] incrementNonce(byte[] nonce) {
var c = 1;
byte[] incrementedNonce = nonce.clone();
c += incrementedNonce[0];
incrementedNonce[0] = (byte) c;

for (int i = 0; i < nonce.length; i++) {
c += (incrementedNonce[i] & 0xFF /*treat as unsigned*/);
incrementedNonce[i] = (byte) c;
c >>= 8;
}

return incrementedNonce;
}

Expand Down

0 comments on commit 4f6fe4a

Please sign in to comment.