[
https://issues.apache.org/jira/browse/HBASE-26613?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Yutong Xiao updated HBASE-26613:
--------------------------------
Description:
{code:java}
public static void incrementIv(byte[] iv, int v) {
int length = iv.length;
boolean carry = true;
// TODO: Optimize for v > 1, e.g. 16, 32
do {
for (int i = 0; i < length; i++) {
if (carry) {
iv[i] = (byte) ((iv[i] + 1) & 0xFF);
carry = 0 == iv[i];
} else {
break;
}
}
v--;
} while (v > 0);
}
{code}
The carry flag is outside the while loop and the inner loop check the carry
value is true, so that when it was set to false, it will make the rest
iterations busy spinning.
And the logic becomes whatever the v is, the IV will be incremented by (1 or
2). As the description in todo, this function should support increment value >
1. So that this is not what we expect I think.
was:
{code:java}
public static void incrementIv(byte[] iv, int v) {
int length = iv.length;
boolean carry = true;
// TODO: Optimize for v > 1, e.g. 16, 32
do {
for (int i = 0; i < length; i++) {
if (carry) {
iv[i] = (byte) ((iv[i] + 1) & 0xFF);
carry = 0 == iv[i];
} else {
break;
}
}
v--;
} while (v > 0);
}
{code}
The carry flag is outside the while loop and the inner loop check the carry
value is true, so that the when it was set to false, it will spinning in the
last iteration. And the logic becomes whatever the v is, the IV will be
incremented by (1 or 2). As the description in todo, this function should
support increment value > 1. So that this is not what we expect I think.
> The logic of the method incrementIV in Encryption class has problem
> -------------------------------------------------------------------
>
> Key: HBASE-26613
> URL: https://issues.apache.org/jira/browse/HBASE-26613
> Project: HBase
> Issue Type: Bug
> Reporter: Yutong Xiao
> Assignee: Yutong Xiao
> Priority: Major
>
> {code:java}
> public static void incrementIv(byte[] iv, int v) {
> int length = iv.length;
> boolean carry = true;
> // TODO: Optimize for v > 1, e.g. 16, 32
> do {
> for (int i = 0; i < length; i++) {
> if (carry) {
> iv[i] = (byte) ((iv[i] + 1) & 0xFF);
> carry = 0 == iv[i];
> } else {
> break;
> }
> }
> v--;
> } while (v > 0);
> }
> {code}
> The carry flag is outside the while loop and the inner loop check the carry
> value is true, so that when it was set to false, it will make the rest
> iterations busy spinning.
> And the logic becomes whatever the v is, the IV will be incremented by (1 or
> 2). As the description in todo, this function should support increment value
> > 1. So that this is not what we expect I think.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)