Record Class BlockGeometry
java.lang.Object
java.lang.Record
zeroecho.core.alg.rsa.BlockGeometry
- Record Components:
inChunkSize- maximum input bytes accepted by one block operationoutChunkSize- maximum output bytes produced by one block operationfinalizationOutputChunks- 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 lengthis 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 Summary
ConstructorsConstructorDescriptionBlockGeometry(int inChunkSize, int outChunkSize, int finalizationOutputChunks) Constructs a new block geometry descriptor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates whether some other object is "equal to" this one.intReturns the value of thefinalizationOutputChunksrecord component.static BlockGeometryforRsa(RsaEncSpec spec, Key key, boolean encrypt) Computes RSA block geometry for the given specification and key.inthashCode()Returns a hash code value for this object.intReturns the value of theinChunkSizerecord component.intReturns the value of theoutChunkSizerecord component.toString()Returns a string representation of this record class.
-
Constructor Details
-
BlockGeometry
public BlockGeometry(int inChunkSize, int outChunkSize, int finalizationOutputChunks) Constructs a new block geometry descriptor.- Parameters:
inChunkSize- maximum input bytes per blockoutChunkSize- output bytes per blockfinalizationOutputChunks- 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
Computes RSA block geometry for the given specification and key.- Parameters:
spec- RSA encryption specification with padding and hash parameterskey- RSA key; must implementRSAKeyencrypt-truefor encryption,falsefor decryption- Returns:
- block geometry with input and output block sizes
- Throws:
IllegalArgumentException- ifkeyis not RSA or modulus is too small
-
equals
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 thecomparemethod from their corresponding wrapper classes. -
hashCode
-
toString
-
inChunkSize
public int inChunkSize()Returns the value of theinChunkSizerecord component.- Returns:
- the value of the
inChunkSizerecord component
-
outChunkSize
public int outChunkSize()Returns the value of theoutChunkSizerecord component.- Returns:
- the value of the
outChunkSizerecord component
-
finalizationOutputChunks
public int finalizationOutputChunks()Returns the value of thefinalizationOutputChunksrecord component.- Returns:
- the value of the
finalizationOutputChunksrecord component
-