Skip to content

Commit

Permalink
Add circe source code to checksum library (apache#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdhabalia authored and merlimat committed Sep 29, 2016
1 parent 26671f6 commit 554f050
Show file tree
Hide file tree
Showing 60 changed files with 4,713 additions and 30 deletions.
10 changes: 9 additions & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ This product contains a modified portion of and depends on 'Protocol Buffers',
Google's data interchange format, which can be obtained at:

* LICENSE:
* license/LICENSE.protobuf.txt (New BSD License)
* protobuf/LICENSE.protobuf.txt
* HOMEPAGE:
* http://code.google.com/p/protobuf/

This product contains a modified portion of and depends on 'circe',
Hash Algorithm Framework & Library, which can be obtained at:

* LICENSE : Apache License, Version 2.0
* HOMEPAGE:
* https://github.com/trevorr/circe

6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ flexible messaging model and an intuitive client API.</description>
<artifactId>powermock-module-testng</artifactId>
<version>1.6.5</version>
</dependency>

<dependency>
<groupId>com.googlecode.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.7</version>
</dependency>

<dependency>
<groupId>org.apache.zookeeper</groupId>
Expand Down
42 changes: 42 additions & 0 deletions protobuf/LICENSE.protobuf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
This license applies to all parts of Protocol Buffers except the following:

- Atomicops support for generic gcc, located in
src/google/protobuf/stubs/atomicops_internals_generic_gcc.h.
This file is copyrighted by Red Hat Inc.

- Atomicops support for AIX/POWER, located in
src/google/protobuf/stubs/atomicops_internals_power.h.
This file is copyrighted by Bloomberg Finance LP.

Copyright 2014, Google Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Code generated by the Protocol Buffer compiler is owned by the owner
of the input file used when generating it. This code is not
standalone and requires a support library to be linked with it. This
support library is itself covered by the above license.
33 changes: 4 additions & 29 deletions pulsar-checksum/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,11 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>com.scurrilous</groupId>
<artifactId>circe-api</artifactId>
<version>1.1-20140603.044855-1</version>
</dependency>


<dependency>
<groupId>com.scurrilous</groupId>
<artifactId>circe-impl</artifactId>
<version>1.1-20140603.044907-1</version>
</dependency>

<dependency>
<groupId>com.scurrilous</groupId>
<artifactId>circe-common</artifactId>
<version>1.1-20140603.044903-1</version>
</dependency>

<dependency>
<groupId>com.scurrilous</groupId>
<artifactId>circe-crc</artifactId>
<version>1.1-20140603.044857-1</version>
<groupId>com.googlecode.jmockit</groupId>
<artifactId>jmockit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
Expand Down Expand Up @@ -183,11 +165,4 @@
</profile>
</profiles>

<repositories>
<repository>
<id>circe-crc-repo</id>
<url>https://oss.sonatype.org/content/repositories/staging</url>
</repository>
</repositories>

</project>
188 changes: 188 additions & 0 deletions pulsar-checksum/src/main/java/com/scurrilous/circe/CommonHashes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/*******************************************************************************
* Copyright 2014 Trevor Robinson
*
* Licensed 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
*
* http://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 com.scurrilous.circe;

import com.scurrilous.circe.params.CrcParameters;
import com.scurrilous.circe.params.MurmurHash3Parameters;
import com.scurrilous.circe.params.MurmurHash3Variant;
import com.scurrilous.circe.params.SimpleHashParameters;
import com.scurrilous.circe.params.SipHash24Parameters;

/**
* Static methods to obtain commonly-used hash functions. Note that a suitable
* provider JAR must be made available on the class path. This class does not
* have direct access to specific implementations; it simply constructs the hash
* parameters and uses the {@link Hashes} class to search for a provider.
*/
public final class CommonHashes {

private CommonHashes() {
}

/**
* Returns an incremental stateless hash function implementing the
* {@linkplain CrcParameters#CRC32 CRC-32} checksum algorithm.
*
* @return a CRC-32 stateless incremental integer hash
* @throws UnsupportedOperationException if no provider is available
*/
public static IncrementalIntHash crc32() {
return Hashes.getIncrementalInt(CrcParameters.CRC32);
}

/**
* Returns an incremental stateless hash function implementing the
* {@linkplain CrcParameters#CRC32C CRC-32C} checksum algorithm.
*
* @return a CRC-32C stateless incremental integer hash
* @throws UnsupportedOperationException if no provider is available
*/
public static IncrementalIntHash crc32c() {
return Hashes.getIncrementalInt(CrcParameters.CRC32C);
}

/**
* Returns an incremental stateless hash function implementing the
* {@linkplain CrcParameters#CRC64 CRC-64} checksum algorithm.
*
* @return a CRC-64 stateless incremental long integer hash
* @throws UnsupportedOperationException if no provider is available
*/
public static IncrementalLongHash crc64() {
return Hashes.getIncrementalLong(CrcParameters.CRC64);
}

/**
* Returns a hash function implementing the MurmurHash3 algorithm, 32-bit
* x86 variant, with a seed of 0.
*
* @return a MurmurHash3 32-bit/x86 stateless integer hash
* @throws UnsupportedOperationException if no provider is available
*/
public static StatelessIntHash murmur3_32() {
return Hashes.getStatelessInt(new MurmurHash3Parameters(MurmurHash3Variant.X86_32));
}

/**
* Returns a hash function implementing the MurmurHash3 algorithm, 32-bit
* x86 variant, with the given seed value
*
* @param seed the 32-bit seed value
* @return a MurmurHash3 32-bit/x86 stateless integer hash
* @throws UnsupportedOperationException if no provider is available
*/
public static StatelessIntHash murmur3_32(int seed) {
return Hashes.getStatelessInt(new MurmurHash3Parameters(MurmurHash3Variant.X86_32, seed));
}

/**
* Returns a hash function implementing the MurmurHash3 algorithm, 128-bit
* x64 variant, with a seed of 0.
*
* @return a MurmurHash3 128-bit/x64 stateful hash
* @throws UnsupportedOperationException if no provider is available
*/
public static StatefulHash murmur3_128() {
return Hashes.createStateful(new MurmurHash3Parameters(MurmurHash3Variant.X64_128));
}

/**
* Returns a hash function implementing the MurmurHash3 algorithm, 128-bit
* x64 variant, with the given seed value.
*
* @param seed the 32-bit seed value
* @return a MurmurHash3 128-bit/x64 stateful hash
* @throws UnsupportedOperationException if no provider is available
*/
public static StatefulHash murmur3_128(int seed) {
return Hashes.createStateful(new MurmurHash3Parameters(MurmurHash3Variant.X64_128, seed));
}

/**
* Returns a hash function implementing the SipHash-2-4 algorithm (64 bits)
* with the default seed,
* {@code 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F}.
*
* @return a SipHash-2-4 stateless long integer hash
* @throws UnsupportedOperationException if no provider is available
*/
public static StatelessLongHash sipHash24() {
return Hashes.getStatelessLong(new SipHash24Parameters());
}

/**
* Returns a hash function implementing the SipHash-2-4 algorithm (64 bits)
* with the given seed value.
*
* @param seedLow the low-order 64 bits of the seed
* @param seedHigh the high-order 64 bits of the seed
* @return a SipHash-2-4 stateless long integer hash
* @throws UnsupportedOperationException if no provider is available
*/
public static StatelessLongHash sipHash24(long seedLow, long seedHigh) {
return Hashes.getStatelessLong(new SipHash24Parameters(seedLow, seedHigh));
}

/**
* Returns a hash function implementing the MD5 algorithm (128 bits).
*
* @return an MD5 stateful hash
* @throws UnsupportedOperationException if no provider is available
*/
public static StatefulHash md5() {
return Hashes.createStateful(SimpleHashParameters.MD5);
}

/**
* Returns a hash function implementing the SHA-1 algorithm (160 bits).
*
* @return a SHA-1 stateful hash
* @throws UnsupportedOperationException if no provider is available
*/
public static StatefulHash sha1() {
return Hashes.createStateful(SimpleHashParameters.SHA1);
}

/**
* Returns a hash function implementing the SHA-256 algorithm (256 bits).
*
* @return a SHA-256 stateful hash
* @throws UnsupportedOperationException if no provider is available
*/
public static StatefulHash sha256() {
return Hashes.createStateful(SimpleHashParameters.SHA256);
}

/**
* Returns a hash function implementing the SHA-384 algorithm (384 bits).
*
* @return a SHA-384 stateful hash
* @throws UnsupportedOperationException if no provider is available
*/
public static StatefulHash sha384() {
return Hashes.createStateful(SimpleHashParameters.SHA384);
}

/**
* Returns a hash function implementing the SHA-512 algorithm (512 bits).
*
* @return a SHA-512 stateful hash
* @throws UnsupportedOperationException if no provider is available
*/
public static StatefulHash sha512() {
return Hashes.createStateful(SimpleHashParameters.SHA512);
}
}
53 changes: 53 additions & 0 deletions pulsar-checksum/src/main/java/com/scurrilous/circe/Hash.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright 2014 Trevor Robinson
*
* Licensed 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
*
* http://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 com.scurrilous.circe;

/**
* Abstract hash function. Each actual hash function is provided using a
* {@linkplain StatefulHash stateful} derived interface. Hash functions with an
* output length that fits within an {@code int} or a {@code long} are also
* generally provided using a {@linkplain StatelessHash stateless} derived
* interface. Given a stateless hash object, a method is provided for obtaining
* a new corresponding stateful object.
*/
public interface Hash {

/**
* Returns the canonical name of this hash algorithm.
*
* @return the name of this hash algorithm
*/
String algorithm();

/**
* Returns the length in bytes of the output of this hash function.
*
* @return the hash length in bytes
*/
int length();

/**
* Returns whether this hash function supports unsafe access to arbitrary
* memory addresses using methods such as
* {@link StatefulHash#update(long, long)},
* {@link StatelessIntHash#calculate(long, long)}, or
* {@link IncrementalIntHash#resume(int, long, long)}. Such functions are
* generally implemented in native code.
*
* @return true if unsafe access is supported, false if not
*/
boolean supportsUnsafe();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright 2014 Trevor Robinson
*
* Licensed 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
*
* http://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 com.scurrilous.circe;

/**
* Base interface implemented by classes describing parameters for a particular
* family of hash algorithms.
*/
public interface HashParameters {

/**
* Returns the canonical name of the hash algorithm.
*
* @return the name of the hash algorithm
*/
String algorithm();
}
Loading

0 comments on commit 554f050

Please sign in to comment.