1 Star 0 Fork 0

origamizyt / Chloryne

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Chloryne - libsodium wrapper

Another libsodium wrapper, with its own scheme.

Installation

Chloryne is available via PyPI:

$ pip install chloryne

Installation requires the presence of libsodium.

Usage

Use the up-level interface Chloride for a full cryptographic scheme.

Key generation:

from chloryne import Chloride
# lib sodium will be initialized automatically

server = Chloride()
client = Chloride()

Key export / import:

server.importKey(client.exportKey())
client.importKey(server.exportKey())

Compute a blake2b-derived shared secret:

assert server.compute() == client.compute()

NOTE: If you want a raw secret use server.privateKey.compute(client.publicKey, raw=True) and vice versa.

Signature (Ed25519):

sig = server.sign(b'data')
assert client.verify(b'data', sig)

NOTE: Signing messages only does not require peer key.

Encryption (Curve25519XSalsa20Poly1305):

ct = server.encrypt(b'data')
assert client.decrypt(ct) == b'data'

NOTE: Decrypting messages only does not require peer key.

Unsafe MAC (fixed key):

mac = server.unsafeMAC()
mac.update(b'data')
digest = mac.finalize()
mac = client.unsafeMAC()
mac.update(b'data')
assert mac.verify(digest)

Safe MAC (ephemeral keys)

eph, mac = server.safeMAC()
mac.update(b'data')
digest = mac.finalize()
mac = client.safeMAC(eph)
mac.update(b'data')
assert mac.verify(digest)

NOTE: Verifying safe MACs only does not require peer key.

Incremental signing:

from chloryne.signers import Signer

signer = Signer()
signer.update(b'data')
sig = signer.sign(server.privateKey)
signer = Signer()
signer.update(b'data')
assert signer.verify(client.peerPublicKey, sig)

Password hashing:

from chloryne.password import Password
import os

# password-based KDF
salt = os.urandom(32) # must be 32-bytes
Password.derive(b'password', salt)

# password storage
strhash = Password.stringify(b'password')
assert Password.verify(b'password', strhash)

Stream Cipher (XChaCha20):

from chloryne.ciphers import StreamCipher
import os

key = os.urandom(32)
sc = StreamCipher(key)
ct = sc.encrypt(b'data') + sc.nonce
# other side...
ct, nonce = ct[:-24], ct[-24:]
sc = StreamCipher(key, nonce)
assert sc.decrypt(ct) == b'data'

NOTE: nonce is b'' before calling encrypt if not provided via constructor.

Store a chloride:

sk = server.privateKey.exportKey()
# sk is a bytes object that can be stored anywhere
server = Chloride(sk)
MIT License Copyright (c) 2022 origamizyt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Another libsodium wrapper. 展开 收起
C 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/origamizyt/chloryne.git
git@gitee.com:origamizyt/chloryne.git
origamizyt
chloryne
Chloryne
master

搜索帮助