Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.crypto.macs;
  
The GMAC specialisation of Galois/Counter mode (GCM) detailed in NIST Special Publication 800-38D.

GMac is an invocation of the GCM mode where no data is encrypted (i.e. all input data to the Mac is processed as additional authenticated data with the underlying GCM block cipher).

 
 public class GMac implements Mac
 {
     private final GCMBlockCipher cipher;
     private final int macSizeBits;

    
Creates a GMAC based on the operation of a block cipher in GCM mode.

This will produce an authentication code the length of the block size of the cipher.

Parameters:
cipher the cipher to be used in GCM mode to generate the MAC.
 
     public GMac(final GCMBlockCipher cipher)
     {
         // use of this confused flow analyser in some earlier JDKs
         this. = cipher;
         this. = 128;
     }

    
Creates a GMAC based on the operation of a 128 bit block cipher in GCM mode.

Parameters:
macSizeBits the mac size to generate, in bits. Must be a multiple of 8 and >= 32 and <= 128. Sizes less than 96 are not recommended, but are supported for specialized applications.
cipher the cipher to be used in GCM mode to generate the MAC.
 
     public GMac(final GCMBlockCipher cipherfinal int macSizeBits)
     {
         this. = cipher;
         this. = macSizeBits;
     }

    
Initialises the GMAC - requires a org.bouncycastle.crypto.params.ParametersWithIV providing a org.bouncycastle.crypto.params.KeyParameter and a nonce.
 
     public void init(final CipherParameters paramsthrows IllegalArgumentException
     {
         if (params instanceof ParametersWithIV)
         {
             final ParametersWithIV param = (ParametersWithIV)params;
 
             final byte[] iv = param.getIV();
             final KeyParameter keyParam = (KeyParameter)param.getParameters();
 
             // GCM is always operated in encrypt mode to calculate MAC
             .init(truenew AEADParameters(keyParamiv));
         }
         else
         {
             throw new IllegalArgumentException("GMAC requires ParametersWithIV");
         }
     }
 
     public String getAlgorithmName()
     {
         return .getUnderlyingCipher().getAlgorithmName() + "-GMAC";
     }
 
     public int getMacSize()
     {
         return  / 8;
     }
 
     public void update(byte inthrows IllegalStateException
     {
         .processAADByte(in);
     }
 
     public void update(byte[] inint inOffint len)
         throws DataLengthExceptionIllegalStateException
     {
         .processAADBytes(ininOfflen);
     }
 
     public int doFinal(byte[] outint outOff)
         throws DataLengthExceptionIllegalStateException
     {
        try
        {
            return .doFinal(outoutOff);
        }
        catch (InvalidCipherTextException e)
        {
            // Impossible in encrypt mode
            throw new IllegalStateException(e.toString());
        }
    }
    public void reset()
    {
        .reset();
    }
New to GrepCode? Check out our FAQ X