427 lines
18 KiB
HTML
427 lines
18 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<!-- NewPage -->
|
|
<html lang="en">
|
|
<head>
|
|
<!-- Generated by javadoc (version 1.7.0_111) on Sun Oct 09 08:50:35 AEST 2016 -->
|
|
<title>CipherState (Noise-Java)</title>
|
|
<meta name="date" content="2016-10-09">
|
|
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
|
|
</head>
|
|
<body>
|
|
<script type="text/javascript"><!--
|
|
if (location.href.indexOf('is-external=true') == -1) {
|
|
parent.document.title="CipherState (Noise-Java)";
|
|
}
|
|
//-->
|
|
</script>
|
|
<noscript>
|
|
<div>JavaScript is disabled on your browser.</div>
|
|
</noscript>
|
|
<!-- ========= START OF TOP NAVBAR ======= -->
|
|
<div class="topNav"><a name="navbar_top">
|
|
<!-- -->
|
|
</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="navList" title="Navigation">
|
|
<li><a href="../../../../com/southernstorm/noise/protocol/package-summary.html">Package</a></li>
|
|
<li class="navBarCell1Rev">Class</li>
|
|
<li><a href="package-tree.html">Tree</a></li>
|
|
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
|
|
<li><a href="../../../../index-all.html">Index</a></li>
|
|
<li><a href="../../../../help-doc.html">Help</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="subNav">
|
|
<ul class="navList">
|
|
<li>Prev Class</li>
|
|
<li><a href="../../../../com/southernstorm/noise/protocol/CipherStatePair.html" title="class in com.southernstorm.noise.protocol"><span class="strong">Next Class</span></a></li>
|
|
</ul>
|
|
<ul class="navList">
|
|
<li><a href="../../../../index.html?com/southernstorm/noise/protocol/CipherState.html" target="_top">Frames</a></li>
|
|
<li><a href="CipherState.html" target="_top">No Frames</a></li>
|
|
</ul>
|
|
<ul class="navList" id="allclasses_navbar_top">
|
|
<li><a href="../../../../allclasses-noframe.html">All Classes</a></li>
|
|
</ul>
|
|
<div>
|
|
<script type="text/javascript"><!--
|
|
allClassesLink = document.getElementById("allclasses_navbar_top");
|
|
if(window==top) {
|
|
allClassesLink.style.display = "block";
|
|
}
|
|
else {
|
|
allClassesLink.style.display = "none";
|
|
}
|
|
//-->
|
|
</script>
|
|
</div>
|
|
<div>
|
|
<ul class="subNavList">
|
|
<li>Summary: </li>
|
|
<li>Nested | </li>
|
|
<li>Field | </li>
|
|
<li>Constr | </li>
|
|
<li><a href="#method_summary">Method</a></li>
|
|
</ul>
|
|
<ul class="subNavList">
|
|
<li>Detail: </li>
|
|
<li>Field | </li>
|
|
<li>Constr | </li>
|
|
<li><a href="#method_detail">Method</a></li>
|
|
</ul>
|
|
</div>
|
|
<a name="skip-navbar_top">
|
|
<!-- -->
|
|
</a></div>
|
|
<!-- ========= END OF TOP NAVBAR ========= -->
|
|
<!-- ======== START OF CLASS DATA ======== -->
|
|
<div class="header">
|
|
<div class="subTitle">com.southernstorm.noise.protocol</div>
|
|
<h2 title="Interface CipherState" class="title">Interface CipherState</h2>
|
|
</div>
|
|
<div class="contentContainer">
|
|
<div class="description">
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<dl>
|
|
<dt>All Superinterfaces:</dt>
|
|
<dd><a href="../../../../com/southernstorm/noise/protocol/Destroyable.html" title="interface in com.southernstorm.noise.protocol">Destroyable</a></dd>
|
|
</dl>
|
|
<hr>
|
|
<br>
|
|
<pre>public interface <span class="strong">CipherState</span>
|
|
extends <a href="../../../../com/southernstorm/noise/protocol/Destroyable.html" title="interface in com.southernstorm.noise.protocol">Destroyable</a></pre>
|
|
<div class="block">Interface to an authenticated cipher for use in the Noise protocol.
|
|
|
|
CipherState objects are used to encrypt or decrypt data during a
|
|
session. Once the handshake has completed, HandshakeState.split()
|
|
will create two CipherState objects for encrypting packets sent to
|
|
the other party, and decrypting packets received from the other party.</div>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="summary">
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<!-- ========== METHOD SUMMARY =========== -->
|
|
<ul class="blockList">
|
|
<li class="blockList"><a name="method_summary">
|
|
<!-- -->
|
|
</a>
|
|
<h3>Method Summary</h3>
|
|
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
|
|
<caption><span>Methods</span><span class="tabEnd"> </span></caption>
|
|
<tr>
|
|
<th class="colFirst" scope="col">Modifier and Type</th>
|
|
<th class="colLast" scope="col">Method and Description</th>
|
|
</tr>
|
|
<tr class="altColor">
|
|
<td class="colFirst"><code>int</code></td>
|
|
<td class="colLast"><code><strong><a href="../../../../com/southernstorm/noise/protocol/CipherState.html#decryptWithAd(byte[],%20byte[],%20int,%20byte[],%20int,%20int)">decryptWithAd</a></strong>(byte[] ad,
|
|
byte[] ciphertext,
|
|
int ciphertextOffset,
|
|
byte[] plaintext,
|
|
int plaintextOffset,
|
|
int length)</code>
|
|
<div class="block">Decrypts a ciphertext buffer using the cipher and a block of associated data.</div>
|
|
</td>
|
|
</tr>
|
|
<tr class="rowColor">
|
|
<td class="colFirst"><code>int</code></td>
|
|
<td class="colLast"><code><strong><a href="../../../../com/southernstorm/noise/protocol/CipherState.html#encryptWithAd(byte[],%20byte[],%20int,%20byte[],%20int,%20int)">encryptWithAd</a></strong>(byte[] ad,
|
|
byte[] plaintext,
|
|
int plaintextOffset,
|
|
byte[] ciphertext,
|
|
int ciphertextOffset,
|
|
int length)</code>
|
|
<div class="block">Encrypts a plaintext buffer using the cipher and a block of associated data.</div>
|
|
</td>
|
|
</tr>
|
|
<tr class="altColor">
|
|
<td class="colFirst"><code><a href="../../../../com/southernstorm/noise/protocol/CipherState.html" title="interface in com.southernstorm.noise.protocol">CipherState</a></code></td>
|
|
<td class="colLast"><code><strong><a href="../../../../com/southernstorm/noise/protocol/CipherState.html#fork(byte[],%20int)">fork</a></strong>(byte[] key,
|
|
int offset)</code>
|
|
<div class="block">Creates a new instance of this cipher and initializes it with a key.</div>
|
|
</td>
|
|
</tr>
|
|
<tr class="rowColor">
|
|
<td class="colFirst"><code>java.lang.String</code></td>
|
|
<td class="colLast"><code><strong><a href="../../../../com/southernstorm/noise/protocol/CipherState.html#getCipherName()">getCipherName</a></strong>()</code>
|
|
<div class="block">Gets the Noise protocol name for this cipher.</div>
|
|
</td>
|
|
</tr>
|
|
<tr class="altColor">
|
|
<td class="colFirst"><code>int</code></td>
|
|
<td class="colLast"><code><strong><a href="../../../../com/southernstorm/noise/protocol/CipherState.html#getKeyLength()">getKeyLength</a></strong>()</code>
|
|
<div class="block">Gets the length of the key values for this cipher.</div>
|
|
</td>
|
|
</tr>
|
|
<tr class="rowColor">
|
|
<td class="colFirst"><code>int</code></td>
|
|
<td class="colLast"><code><strong><a href="../../../../com/southernstorm/noise/protocol/CipherState.html#getMACLength()">getMACLength</a></strong>()</code>
|
|
<div class="block">Gets the length of the MAC values for this cipher.</div>
|
|
</td>
|
|
</tr>
|
|
<tr class="altColor">
|
|
<td class="colFirst"><code>boolean</code></td>
|
|
<td class="colLast"><code><strong><a href="../../../../com/southernstorm/noise/protocol/CipherState.html#hasKey()">hasKey</a></strong>()</code>
|
|
<div class="block">Determine if this cipher object has been configured with a key.</div>
|
|
</td>
|
|
</tr>
|
|
<tr class="rowColor">
|
|
<td class="colFirst"><code>void</code></td>
|
|
<td class="colLast"><code><strong><a href="../../../../com/southernstorm/noise/protocol/CipherState.html#initializeKey(byte[],%20int)">initializeKey</a></strong>(byte[] key,
|
|
int offset)</code>
|
|
<div class="block">Initializes the key on this cipher object.</div>
|
|
</td>
|
|
</tr>
|
|
<tr class="altColor">
|
|
<td class="colFirst"><code>void</code></td>
|
|
<td class="colLast"><code><strong><a href="../../../../com/southernstorm/noise/protocol/CipherState.html#setNonce(long)">setNonce</a></strong>(long nonce)</code>
|
|
<div class="block">Sets the nonce value.</div>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<ul class="blockList">
|
|
<li class="blockList"><a name="methods_inherited_from_class_com.southernstorm.noise.protocol.Destroyable">
|
|
<!-- -->
|
|
</a>
|
|
<h3>Methods inherited from interface com.southernstorm.noise.protocol.<a href="../../../../com/southernstorm/noise/protocol/Destroyable.html" title="interface in com.southernstorm.noise.protocol">Destroyable</a></h3>
|
|
<code><a href="../../../../com/southernstorm/noise/protocol/Destroyable.html#destroy()">destroy</a></code></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
<div class="details">
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<!-- ============ METHOD DETAIL ========== -->
|
|
<ul class="blockList">
|
|
<li class="blockList"><a name="method_detail">
|
|
<!-- -->
|
|
</a>
|
|
<h3>Method Detail</h3>
|
|
<a name="getCipherName()">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>getCipherName</h4>
|
|
<pre>java.lang.String getCipherName()</pre>
|
|
<div class="block">Gets the Noise protocol name for this cipher.</div>
|
|
<dl><dt><span class="strong">Returns:</span></dt><dd>The cipher name.</dd></dl>
|
|
</li>
|
|
</ul>
|
|
<a name="getKeyLength()">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>getKeyLength</h4>
|
|
<pre>int getKeyLength()</pre>
|
|
<div class="block">Gets the length of the key values for this cipher.</div>
|
|
<dl><dt><span class="strong">Returns:</span></dt><dd>The length of the key in bytes; usually 32.</dd></dl>
|
|
</li>
|
|
</ul>
|
|
<a name="getMACLength()">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>getMACLength</h4>
|
|
<pre>int getMACLength()</pre>
|
|
<div class="block">Gets the length of the MAC values for this cipher.</div>
|
|
<dl><dt><span class="strong">Returns:</span></dt><dd>The length of MAC values in bytes, or zero if the
|
|
key has not yet been initialized.</dd></dl>
|
|
</li>
|
|
</ul>
|
|
<a name="initializeKey(byte[], int)">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>initializeKey</h4>
|
|
<pre>void initializeKey(byte[] key,
|
|
int offset)</pre>
|
|
<div class="block">Initializes the key on this cipher object.</div>
|
|
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>key</code> - Points to a buffer that contains the key.</dd><dd><code>offset</code> - The offset of the key in the key buffer.
|
|
|
|
The key buffer must contain at least getKeyLength() bytes
|
|
starting at offset.</dd><dt><span class="strong">See Also:</span></dt><dd><a href="../../../../com/southernstorm/noise/protocol/CipherState.html#hasKey()"><code>hasKey()</code></a></dd></dl>
|
|
</li>
|
|
</ul>
|
|
<a name="hasKey()">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>hasKey</h4>
|
|
<pre>boolean hasKey()</pre>
|
|
<div class="block">Determine if this cipher object has been configured with a key.</div>
|
|
<dl><dt><span class="strong">Returns:</span></dt><dd>true if this cipher object has a key; false if the
|
|
key has not yet been set with initializeKey().</dd><dt><span class="strong">See Also:</span></dt><dd><a href="../../../../com/southernstorm/noise/protocol/CipherState.html#initializeKey(byte[],%20int)"><code>initializeKey(byte[], int)</code></a></dd></dl>
|
|
</li>
|
|
</ul>
|
|
<a name="encryptWithAd(byte[], byte[], int, byte[], int, int)">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>encryptWithAd</h4>
|
|
<pre>int encryptWithAd(byte[] ad,
|
|
byte[] plaintext,
|
|
int plaintextOffset,
|
|
byte[] ciphertext,
|
|
int ciphertextOffset,
|
|
int length)
|
|
throws javax.crypto.ShortBufferException</pre>
|
|
<div class="block">Encrypts a plaintext buffer using the cipher and a block of associated data.</div>
|
|
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>ad</code> - The associated data, or null if there is none.</dd><dd><code>plaintext</code> - The buffer containing the plaintext to encrypt.</dd><dd><code>plaintextOffset</code> - The offset within the plaintext buffer of the
|
|
first byte or plaintext data.</dd><dd><code>ciphertext</code> - The buffer to place the ciphertext in. This can
|
|
be the same as the plaintext buffer.</dd><dd><code>ciphertextOffset</code> - The first offset within the ciphertext buffer
|
|
to place the ciphertext and the MAC tag.</dd><dd><code>length</code> - The length of the plaintext.</dd>
|
|
<dt><span class="strong">Returns:</span></dt><dd>The length of the ciphertext plus the MAC tag, or -1 if the
|
|
ciphertext buffer is not large enough to hold the result.</dd>
|
|
<dt><span class="strong">Throws:</span></dt>
|
|
<dd><code>javax.crypto.ShortBufferException</code> - The ciphertext buffer does not have
|
|
enough space to hold the ciphertext plus MAC.</dd>
|
|
<dd><code>java.lang.IllegalStateException</code> - The nonce has wrapped around.
|
|
|
|
The plaintext and ciphertext buffers can be the same for in-place
|
|
encryption. In that case, plaintextOffset must be identical to
|
|
ciphertextOffset.
|
|
|
|
There must be enough space in the ciphertext buffer to accomodate
|
|
length + getMACLength() bytes of data starting at ciphertextOffset.</dd></dl>
|
|
</li>
|
|
</ul>
|
|
<a name="decryptWithAd(byte[], byte[], int, byte[], int, int)">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>decryptWithAd</h4>
|
|
<pre>int decryptWithAd(byte[] ad,
|
|
byte[] ciphertext,
|
|
int ciphertextOffset,
|
|
byte[] plaintext,
|
|
int plaintextOffset,
|
|
int length)
|
|
throws javax.crypto.ShortBufferException,
|
|
javax.crypto.BadPaddingException</pre>
|
|
<div class="block">Decrypts a ciphertext buffer using the cipher and a block of associated data.</div>
|
|
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>ad</code> - The associated data, or null if there is none.</dd><dd><code>ciphertext</code> - The buffer containing the ciphertext to decrypt.</dd><dd><code>ciphertextOffset</code> - The offset within the ciphertext buffer of
|
|
the first byte of ciphertext data.</dd><dd><code>plaintext</code> - The buffer to place the plaintext in. This can be
|
|
the same as the ciphertext buffer.</dd><dd><code>plaintextOffset</code> - The first offset within the plaintext buffer
|
|
to place the plaintext.</dd><dd><code>length</code> - The length of the incoming ciphertext plus the MAC tag.</dd>
|
|
<dt><span class="strong">Returns:</span></dt><dd>The length of the plaintext with the MAC tag stripped off.</dd>
|
|
<dt><span class="strong">Throws:</span></dt>
|
|
<dd><code>javax.crypto.ShortBufferException</code> - The plaintext buffer does not have
|
|
enough space to store the decrypted data.</dd>
|
|
<dd><code>javax.crypto.BadPaddingException</code> - The MAC value failed to verify.</dd>
|
|
<dd><code>java.lang.IllegalStateException</code> - The nonce has wrapped around.
|
|
|
|
The plaintext and ciphertext buffers can be the same for in-place
|
|
decryption. In that case, ciphertextOffset must be identical to
|
|
plaintextOffset.</dd></dl>
|
|
</li>
|
|
</ul>
|
|
<a name="fork(byte[], int)">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockList">
|
|
<li class="blockList">
|
|
<h4>fork</h4>
|
|
<pre><a href="../../../../com/southernstorm/noise/protocol/CipherState.html" title="interface in com.southernstorm.noise.protocol">CipherState</a> fork(byte[] key,
|
|
int offset)</pre>
|
|
<div class="block">Creates a new instance of this cipher and initializes it with a key.</div>
|
|
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>key</code> - The buffer containing the key.</dd><dd><code>offset</code> - The offset into the key buffer of the first key byte.</dd>
|
|
<dt><span class="strong">Returns:</span></dt><dd>A new CipherState of the same class as this one.</dd></dl>
|
|
</li>
|
|
</ul>
|
|
<a name="setNonce(long)">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="blockListLast">
|
|
<li class="blockList">
|
|
<h4>setNonce</h4>
|
|
<pre>void setNonce(long nonce)</pre>
|
|
<div class="block">Sets the nonce value.</div>
|
|
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>nonce</code> - The new nonce value, which must be greater than or equal
|
|
to the current value.
|
|
|
|
This function is intended for testing purposes only. If the nonce
|
|
value goes backwards then security may be compromised.</dd></dl>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<!-- ========= END OF CLASS DATA ========= -->
|
|
<!-- ======= START OF BOTTOM NAVBAR ====== -->
|
|
<div class="bottomNav"><a name="navbar_bottom">
|
|
<!-- -->
|
|
</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
|
|
<!-- -->
|
|
</a>
|
|
<ul class="navList" title="Navigation">
|
|
<li><a href="../../../../com/southernstorm/noise/protocol/package-summary.html">Package</a></li>
|
|
<li class="navBarCell1Rev">Class</li>
|
|
<li><a href="package-tree.html">Tree</a></li>
|
|
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
|
|
<li><a href="../../../../index-all.html">Index</a></li>
|
|
<li><a href="../../../../help-doc.html">Help</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="subNav">
|
|
<ul class="navList">
|
|
<li>Prev Class</li>
|
|
<li><a href="../../../../com/southernstorm/noise/protocol/CipherStatePair.html" title="class in com.southernstorm.noise.protocol"><span class="strong">Next Class</span></a></li>
|
|
</ul>
|
|
<ul class="navList">
|
|
<li><a href="../../../../index.html?com/southernstorm/noise/protocol/CipherState.html" target="_top">Frames</a></li>
|
|
<li><a href="CipherState.html" target="_top">No Frames</a></li>
|
|
</ul>
|
|
<ul class="navList" id="allclasses_navbar_bottom">
|
|
<li><a href="../../../../allclasses-noframe.html">All Classes</a></li>
|
|
</ul>
|
|
<div>
|
|
<script type="text/javascript"><!--
|
|
allClassesLink = document.getElementById("allclasses_navbar_bottom");
|
|
if(window==top) {
|
|
allClassesLink.style.display = "block";
|
|
}
|
|
else {
|
|
allClassesLink.style.display = "none";
|
|
}
|
|
//-->
|
|
</script>
|
|
</div>
|
|
<div>
|
|
<ul class="subNavList">
|
|
<li>Summary: </li>
|
|
<li>Nested | </li>
|
|
<li>Field | </li>
|
|
<li>Constr | </li>
|
|
<li><a href="#method_summary">Method</a></li>
|
|
</ul>
|
|
<ul class="subNavList">
|
|
<li>Detail: </li>
|
|
<li>Field | </li>
|
|
<li>Constr | </li>
|
|
<li><a href="#method_detail">Method</a></li>
|
|
</ul>
|
|
</div>
|
|
<a name="skip-navbar_bottom">
|
|
<!-- -->
|
|
</a></div>
|
|
<!-- ======== END OF BOTTOM NAVBAR ======= -->
|
|
</body>
|
|
</html>
|