ConstantTimeUtils.java — netty Source File
Architecture documentation for ConstantTimeUtils.java, a java file in the netty codebase.
Entity Profile
Relationship Graph
Source Code
/*
* Copyright 2016 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.util.internal;
public final class ConstantTimeUtils {
private ConstantTimeUtils() { }
/**
* Compare two {@code int}s without leaking timing information.
* <p>
* The {@code int} return type is intentional and is designed to allow cascading of constant time operations:
* <pre>
* int l1 = 1;
* int l2 = 1;
* int l3 = 1;
* int l4 = 500;
* boolean equals = (equalsConstantTime(l1, l2) & equalsConstantTime(l3, l4)) != 0;
* </pre>
* @param x the first value.
* @param y the second value.
* @return {@code 0} if not equal. {@code 1} if equal.
*/
public static int equalsConstantTime(int x, int y) {
int z = ~(x ^ y);
z &= z >> 16;
z &= z >> 8;
z &= z >> 4;
z &= z >> 2;
z &= z >> 1;
return z & 1;
}
/**
* Compare two {@code longs}s without leaking timing information.
* <p>
* The {@code int} return type is intentional and is designed to allow cascading of constant time operations:
* <pre>
* long l1 = 1;
* long l2 = 1;
* long l3 = 1;
* long l4 = 500;
* boolean equals = (equalsConstantTime(l1, l2) & equalsConstantTime(l3, l4)) != 0;
* </pre>
* @param x the first value.
* @param y the second value.
* @return {@code 0} if not equal. {@code 1} if equal.
*/
// ... (72 more lines)
Domain
Subdomains
Classes
Source
Frequently Asked Questions
What does ConstantTimeUtils.java do?
ConstantTimeUtils.java is a source file in the netty codebase, written in java. It belongs to the CommonUtil domain, Internal subdomain.
Where is ConstantTimeUtils.java in the architecture?
ConstantTimeUtils.java is located at common/src/main/java/io/netty/util/internal/ConstantTimeUtils.java (domain: CommonUtil, subdomain: Internal, directory: common/src/main/java/io/netty/util/internal).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free