Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kayem Logo

Kayem

This is the main source repository for Kayem. It will contain the compiler and the standard library.

Why Kayem?

  • Simplicity & performance: Kayem aims to provide performance similar to Rust while offering a simpler syntax and development experience.

  • Rich standard library: Kayem will provide a rich standard library with strong compatibility with the compiler to enable better optimizations and performance.

  • Easily debuggable: Kayem compiles to Rust. Therefore, analyzing Kayem-generated code is more human-friendly than analyzing LLVM IR or assembly code directly.

Why not Kayem?

  • Maturity: Kayem is not yet mature. The compiler is still under development and the standard library is currently empty.

  • Deployment & development tools: Kayem is not yet easy to deploy or use in production. It does not currently provide tools such as Cargo, an LSP, or a VSCode extension.

  • Compilation time: Rust is known for relatively long compilation times. Since Kayem adds an additional layer over Rust and performs its own optimizations, compilation times may increase.

  • Low-level control: Kayem is not designed to replace low-level languages such as C or Rust for every use case. Developers requiring complete control over memory operations, hardware interactions, or highly specialized optimizations may still need lower-level languages. Some critical libraries, especially cryptographic ones, may continue to be written directly in Rust or C.

Rust or Kayem ?

Since Kayem produces Rust code, why not coding directly in Rust ?

Because Rust philosophy is different from Kayem's one. For example, in Rust, ownership and mutability have to be explicitely given by the user, while in Kayem, the user only expresses a will, that the compiler optimizes into Rust code. Also, Kayem compiler optimizes at high level (directly on algorithms), while Rust performs low-level optimizations. So, if you want many of the benefits of Rust, without all the ownership, borrowing, lifetimes rules, and you want to contribute to a small language, try Kayem. Anyway, if you want a low-level control over your code, all Rust benefits and a mature ecosystem, choose Rust.

Overview

Here is a pseudo-implementation of a Saber encapsulation in Rust and Kayem:

pub struct SaberEncapsulated {
    pub ciphertext: SaberCiphertext, // The ciphertext
    pub mac: Box<[u8]>, // The MAC: hash(pk, secret)
    pub exported: SaberExported, // Exported parameters: NTT tables are not exported because they are too large
}

impl SaberEncapsulated {
    pub fn new(ciphertext: SaberCiphertext, mac: Box<[u8]>, exported: SaberExported) -> Self {
        Self { ciphertext, mac, exported }
    }
}

impl Saber {
    pub fn encapsulate(&self, public_key: &SaberPublicKey) -> Result<(Vec<u8>, Vec<u8>), SaberError> {
        let key = Polynomial::random_binary(self.params.n);

        let ciphertext = self.encrypt(public_key, &key);

        let mut mac_plain = public_key.b.as_bytes().to_vec();
        mac_plain.extend_from_slice(key.as_bytes());

        let mac = blake3::hash(&mac_plain)
            .as_bytes()
            .to_vec()
            .into_boxed_slice();

        let exported = self.to_export();

        let saber_enc = SaberEncapsulated::new(ciphertext, mac, exported);

        let bytes_enc = match to_allocvec(&saber_enc) {
            Ok(v) => v,
            Err(e) => return Err(SaberError::SerializationError(e)),
        };

        let shared_key = blake3::hash(key.as_bytes()).as_bytes().to_vec();

        Ok((shared_key, bytes_enc))
    }
}
struct SaberEncapsulated {
    ciphertext: SaberCiphertext,
    mac: [num],
    exported: SaberExported,
}

autoimpl new for SaberEncapsulated;

impl Saber {
    result<(Vec<num>, Vec<num>), SaberError> encapsulate(self, public_key: SaberPublicKey) {

        key = poly.random_binary(self.params.n);

        ciphertext = self.encrypt(public_key, key);

        mac_plain = public_key.b;
        mac_plain += key // Concatenates the key and the public key B [Key B || Key]

        mac = hash(mac_plain);

        exported = self.to_export();

        saber_enc = SaberEncapsulated.new(ciphertext, mac, exported);

        bytes_enc = serialize(saber_enc)!; // ! automatically propagates errors and converts errors (no need of `impl From<SerializeError>...)

        shared_key = hash(key);

        Ok<(shared_key, bytes_enc)>
    }
}

As shown above, Kayem automatically handles concepts such as type inference, ownership, borrowing, and lifetimes. The Kayem syntax is designed to be simpler while still allowing usefull features such as automatic implementations.

Since Kayem is a high-level layer compiling to Rust, many libraries (especially security-critical ones such as cryptographic libraries) can continue to be written directly in Rust or adapted from existing crates.

For more information, see the overview.

Development notes

I think the compiler is for now completed at 25 %, since we already have some basics (lexer, parser, tokens, ast...) but many layers remains to be created, and existing ones aren't complete.

License

Kayem is licensed under the CECILL-C license and the Apache 2.0 license.

About

This is the main source repository for Kayem language, a high-level language that compiles to Rust and manages automatically ownership, types inference and optimizations.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages