org.apache.directory.server.kerberos.shared.crypto.encryption
Class NFold

java.lang.Object
  extended by org.apache.directory.server.kerberos.shared.crypto.encryption.NFold

public class NFold
extends java.lang.Object

An implementation of the n-fold algorithm, as required by RFC 3961, "Encryption and Checksum Specifications for Kerberos 5." "To n-fold a number X, replicate the input value to a length that is the least common multiple of n and the length of X. Before each repetition, the input is rotated to the right by 13 bit positions. The successive n-bit chunks are added together using 1's-complement addition (that is, with end-around carry) to yield a n-bit result."

Version:
$Rev$, $Date$
Author:
Apache Directory Project

Constructor Summary
NFold()
           
 
Method Summary
protected static int getLcm(int n1, int n2)
          For 2 numbers, return the least-common multiple.
static byte[] nFold(int n, byte[] data)
          N-fold the data n times.
protected static byte[] sum(byte[] n1, byte[] n2, int len)
          Perform one's complement addition (addition with end-around carry).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NFold

public NFold()
Method Detail

nFold

public static byte[] nFold(int n,
                           byte[] data)
N-fold the data n times.

Parameters:
n - The number of times to n-fold the data.
data - The data to n-fold.
Returns:
The n-folded data.

getLcm

protected static int getLcm(int n1,
                            int n2)
For 2 numbers, return the least-common multiple.

Parameters:
n1 - The first number.
n2 - The second number.
Returns:
The least-common multiple.

sum

protected static byte[] sum(byte[] n1,
                            byte[] n2,
                            int len)
Perform one's complement addition (addition with end-around carry). Note that for purposes of n-folding, we do not actually complement the result of the addition.

Parameters:
n1 - The first number.
n2 - The second number.
len - The length of the byte arrays to sum.
Returns:
The sum with end-around carry.


Copyright © 2003-2009 Apache Software Foundation. All Rights Reserved.