-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Variable-length onion payloads (#976)
Add support for variable-length onion payloads at the Sphinx (cryptographic) layer. This is currently unused as we keep using the legacy format by default (this will be changed in a later commit). This commit also refactors quite heavily the Sphinx file.
- Loading branch information
Showing
44 changed files
with
1,195 additions
and
694 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
eclair-core/src/main/scala/fr/acinq/eclair/crypto/Mac.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2019 ACINQ SAS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package fr.acinq.eclair.crypto | ||
|
||
import fr.acinq.bitcoin.ByteVector32 | ||
import org.spongycastle.crypto.digests.SHA256Digest | ||
import org.spongycastle.crypto.macs.HMac | ||
import org.spongycastle.crypto.params.KeyParameter | ||
import scodec.bits.ByteVector | ||
|
||
/** | ||
* Created by t-bast on 04/07/19. | ||
*/ | ||
|
||
/** | ||
* Create and verify message authentication codes. | ||
*/ | ||
trait Mac32 { | ||
|
||
def mac(message: ByteVector): ByteVector32 | ||
|
||
def verify(mac: ByteVector32, message: ByteVector): Boolean | ||
|
||
} | ||
|
||
case class Hmac256(key: ByteVector) extends Mac32 { | ||
|
||
override def mac(message: ByteVector): ByteVector32 = Mac32.hmac256(key, message) | ||
|
||
override def verify(mac: ByteVector32, message: ByteVector): Boolean = this.mac(message) === mac | ||
|
||
} | ||
|
||
object Mac32 { | ||
|
||
def hmac256(key: ByteVector, message: ByteVector): ByteVector32 = { | ||
val mac = new HMac(new SHA256Digest()) | ||
mac.init(new KeyParameter(key.toArray)) | ||
mac.update(message.toArray, 0, message.length.toInt) | ||
val output = new Array[Byte](32) | ||
mac.doFinal(output, 0) | ||
ByteVector32(ByteVector.view(output)) | ||
} | ||
|
||
} |
Oops, something went wrong.