Record Class BlockGeometry

java.lang.Object
java.lang.Record
zeroecho.core.alg.rsa.BlockGeometry
Record Components:
inChunkSize - maximum input bytes accepted by one block operation
outChunkSize - maximum output bytes produced by one block operation
finalizationOutputChunks - additional output chunks reserved for finalization

public record BlockGeometry(int inChunkSize, int outChunkSize, int finalizationOutputChunks) extends Record
Describes block sizing rules for RSA encryption and decryption.

A BlockGeometry defines how many plaintext or ciphertext bytes can be processed per block and how many bytes are emitted, given an RSA modulus, padding scheme, and direction (encryption or decryption). This information is required by RsaCipherContext to configure the CipherTransformInputStreamBuilder for streaming operation.

RSA rules

  • Encryption:
    • Input block size is the modulus length minus padding overhead.
    • Output block size is exactly the modulus length in bytes.
  • Decryption:
    • Input block size is exactly the modulus length in bytes.
    • Output block size is bounded by the encryption input maximum, but modulus length is used as a safe upper bound.

Example

Key pub = ...; // RSA public key
RsaEncSpec spec = RsaEncSpec.ofPkcs1v15();
BlockGeometry g = BlockGeometry.forRsa(spec, pub, true);
System.out.printf("Plaintext block: %d, Ciphertext block: %d%n",
                  g.inChunkSize(), g.outChunkSize());
Since:
1.0
  • Constructor Details

    • BlockGeometry

      public BlockGeometry(int inChunkSize, int outChunkSize, int finalizationOutputChunks)
      Constructs a new block geometry descriptor.
      Parameters:
      inChunkSize - maximum input bytes per block
      outChunkSize - output bytes per block
      finalizationOutputChunks - number of additional chunks during finalization
      Throws:
      IllegalArgumentException - if input size is not greater than one, output size is not positive, input exceeds output, or finalization chunks is not zero
  • Method Details

    • forRsa

      public static BlockGeometry forRsa(RsaEncSpec spec, Key key, boolean encrypt)
      Computes RSA block geometry for the given specification and key.
      Parameters:
      spec - RSA encryption specification with padding and hash parameters
      key - RSA key; must implement RSAKey
      encrypt - true for encryption, false for decryption
      Returns:
      block geometry with input and output block sizes
      Throws:
      IllegalArgumentException - if key is not RSA or modulus is too small
    • equals

      public boolean equals(Object other)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      other - the object with which to compare
      Returns:
      true if this object is the same as the other argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • inChunkSize

      public int inChunkSize()
      Returns the value of the inChunkSize record component.
      Returns:
      the value of the inChunkSize record component
    • outChunkSize

      public int outChunkSize()
      Returns the value of the outChunkSize record component.
      Returns:
      the value of the outChunkSize record component
    • finalizationOutputChunks

      public int finalizationOutputChunks()
      Returns the value of the finalizationOutputChunks record component.
      Returns:
      the value of the finalizationOutputChunks record component