├── NTRU ├── NTRU-GPU-509 │ ├── bin │ │ ├── check.o │ │ ├── main.o │ │ ├── packq.o │ │ ├── poly.o │ │ └── cuda_kernel.o │ ├── include │ │ ├── check.cuh │ │ ├── cuda_kernel.cuh │ │ ├── packq.cuh │ │ ├── params.h │ │ ├── poly.cuh │ │ └── tv.h │ ├── main.cu │ ├── Makefile │ └── src │ │ ├── check.cu │ │ ├── poly.cu │ │ ├── packq.cu │ │ └── cuda_kernel.cu └── NTRU-GPU-677 │ ├── bin │ ├── check.o │ ├── main.o │ ├── packq.o │ ├── poly.o │ └── cuda_kernel.o │ ├── include │ ├── check.cuh │ ├── cuda_kernel.cuh │ ├── packq.cuh │ ├── params.h │ ├── poly.cuh │ └── tv.h │ ├── main.cu │ ├── Makefile │ └── src │ ├── check.cu │ ├── poly.cu │ ├── packq.cu │ └── cuda_kernel.cu ├── TensorTRU ├── Makefile ├── params.h └── TensorTRU.cu ├── TensorLAC ├── params.h ├── Makefile └── TensorLAC.cu ├── TensorFro ├── params.h ├── Makefile └── TensorFro.cu ├── README.md └── LICENSE /NTRU/NTRU-GPU-509/bin/check.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benlwk/Tensorcrypto/HEAD/NTRU/NTRU-GPU-509/bin/check.o -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-509/bin/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benlwk/Tensorcrypto/HEAD/NTRU/NTRU-GPU-509/bin/main.o -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-509/bin/packq.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benlwk/Tensorcrypto/HEAD/NTRU/NTRU-GPU-509/bin/packq.o -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-509/bin/poly.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benlwk/Tensorcrypto/HEAD/NTRU/NTRU-GPU-509/bin/poly.o -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/bin/check.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benlwk/Tensorcrypto/HEAD/NTRU/NTRU-GPU-677/bin/check.o -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/bin/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benlwk/Tensorcrypto/HEAD/NTRU/NTRU-GPU-677/bin/main.o -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/bin/packq.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benlwk/Tensorcrypto/HEAD/NTRU/NTRU-GPU-677/bin/packq.o -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/bin/poly.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benlwk/Tensorcrypto/HEAD/NTRU/NTRU-GPU-677/bin/poly.o -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-509/bin/cuda_kernel.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benlwk/Tensorcrypto/HEAD/NTRU/NTRU-GPU-509/bin/cuda_kernel.o -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/bin/cuda_kernel.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benlwk/Tensorcrypto/HEAD/NTRU/NTRU-GPU-677/bin/cuda_kernel.o -------------------------------------------------------------------------------- /TensorTRU/Makefile: -------------------------------------------------------------------------------- 1 | all: TensorTRU.cu 2 | nvcc -o TensorTRU -arch=sm_75 TensorTRU.cu 3 | 4 | clean: 5 | rm -f TensorTRU 6 | 7 | 8 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/include/check.cuh: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "../include/cuda_kernel.cuh" 4 | #include "../include/params.h" 5 | 6 | __global__ void owcpa_check_ciphertext_gpu(int *fail, uint8_t *ciphertext); 7 | 8 | __global__ void owcpa_check_r_gpu(int *fail, uint16_t *r); 9 | 10 | __global__ void owcpa_check_m_gpu(int *fail, uint16_t *m); 11 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-509/include/check.cuh: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../include/cuda_kernel.cuh" 4 | #include "../include/params.h" 5 | 6 | __global__ void owcpa_check_ciphertext_gpu(int *fail, uint8_t *ciphertext); 7 | 8 | __global__ void owcpa_check_r_gpu(int *fail, uint16_t *r); 9 | 10 | __global__ void owcpa_check_m_gpu(int *fail, uint16_t *m); 11 | -------------------------------------------------------------------------------- /TensorLAC/params.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define LAC_Q 251 6 | #define LAC128 // comment out for LAC192/256 7 | 8 | #ifdef LAC128 9 | #define LAC_N 512 10 | #else 11 | #define LAC_N 1024 12 | #endif 13 | 14 | #define WMMA_THREAD LAC_N 15 | #define REPEAT 100 // Measure average time 16 | #define DEBUG // Print the results of polynomial convolution 17 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/include/cuda_kernel.cuh: -------------------------------------------------------------------------------- 1 | #define NTRU_N_PWR2 704 // Multiple of 32 2 | #define PADDING 27 // 704 - 27 = 677 3 | #define K 672 // Multiple of 16 4 | #define BATCH K 5 | #define DEBUG // To check the encryption/decryption results 6 | 7 | #define MODQ(X) ((X) & (NTRU_Q-1)) 8 | 9 | void ntru_enc(uint8_t mode, uint16_t *h_m, uint16_t *h_r, uint8_t *h_pk, uint8_t *h_c) ; 10 | void ntru_dec(uint8_t mode, uint8_t *h_rm, uint8_t *h_c, uint8_t *h_sk, uint16_t *h_m) ; 11 | 12 | 13 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-509/include/cuda_kernel.cuh: -------------------------------------------------------------------------------- 1 | #define NTRU_N_PWR2 512 // Multiple of 32 2 | #define PADDING 3 // 512 - 3 = 509 3 | #define K 496 // Multiple of 16 4 | #define BATCH K 5 | #define DEBUG // To check the encryption/decryption results 6 | 7 | #define MODQ(X) ((X) & (NTRU_Q-1)) 8 | 9 | 10 | void ntru_enc(uint8_t mode, uint16_t *h_m, uint16_t *h_r, uint8_t *h_pk, uint8_t *h_c) ; 11 | void ntru_dec(uint8_t mode, uint8_t *h_rm, uint8_t *h_c, uint8_t *h_sk, uint16_t *h_m) ; 12 | 13 | 14 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-509/include/packq.cuh: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../include/cuda_kernel.cuh" 4 | __global__ void poly_Rq_sum_zero_frombytes_gpu(uint16_t *r, unsigned char *a); 5 | __global__ void poly_Sq_tobytes_gpu(unsigned char *r, const uint16_t *a); 6 | __global__ void poly_Rq_sum_zero_frombytes_sum_gpu(uint16_t *r); 7 | __global__ void poly_S3_frombytes_gpu(uint16_t *r, uint8_t* msg); 8 | __global__ void poly_S3_tobytes_gpu(uint8_t msg[NTRU_OWCPA_MSGBYTES], uint16_t *a); 9 | __global__ void poly_Sq_frombytes_gpu_global(uint16_t *r, const unsigned char *a); -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/include/packq.cuh: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../include/cuda_kernel.cuh" 4 | __global__ void poly_Rq_sum_zero_frombytes_gpu(uint16_t *r, unsigned char *a); 5 | __global__ void poly_Sq_tobytes_gpu(unsigned char *r, const uint16_t *a); 6 | __global__ void poly_Rq_sum_zero_frombytes_sum_gpu(uint16_t *r); 7 | __global__ void poly_S3_frombytes_gpu(uint16_t *r, uint8_t* msg); 8 | __global__ void poly_S3_tobytes_gpu(uint8_t msg[NTRU_OWCPA_MSGBYTES], uint16_t *a); 9 | __global__ void poly_Sq_frombytes_gpu_global(uint16_t *r, const unsigned char *a); -------------------------------------------------------------------------------- /TensorFro/params.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define FRO_Q 2048 6 | 7 | // #define FRODO_II // Select one of these two 8 | #define TENSORFRO 9 | 10 | #define CLIENT // Select client or server 11 | // #define SERVER 12 | 13 | #ifdef FRODO_II 14 | #define FRO_N_PWR2 576 // Multiple of 32 15 | #define PADDING 6 16 | #define FRO_N FRO_N_PWR2 - PADDING 17 | #ifdef CLIENT 18 | #define K 512 19 | #else 20 | #define K 570 21 | #endif 22 | #endif 23 | 24 | #ifdef TENSORFRO 25 | #define FRO_N_PWR2 576 // Multiple of 32 26 | #define PADDING 16 27 | #define FRO_N FRO_N_PWR2 - PADDING 28 | #ifdef CLIENT 29 | #define K 552 30 | #else 31 | #define K 550 32 | #endif 33 | #endif 34 | 35 | #define WMMA_THREAD FRO_N_PWR2 36 | #define REPEAT 1 37 | #define DEBUG -------------------------------------------------------------------------------- /TensorTRU/params.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define NTRU_Q 2048 // For hps2048509 and hps2048677 6 | #define NTRUHPS2048509 // Select only one of these two 7 | // #define NTRUHPS2048677 8 | 9 | #define ENCRYPT 10 | 11 | #ifdef NTRUHPS2048509 12 | #define NTRU_N_PWR2 512 // Multiple of 32 13 | #define PADDING 3 14 | #define K 512 15 | #define NTRU_N NTRU_N_PWR2 - PADDING // 512 - 3 = 509 16 | #endif 17 | 18 | #ifdef NTRUHPS2048677 19 | #define NTRU_N_PWR2 704 // Multiple of 32 20 | #define PADDING 27 21 | #define K 704 22 | #define NTRU_N NTRU_N_PWR2 - PADDING // 704 - 27 = 677 23 | #endif 24 | 25 | #define WMMA_THREAD NTRU_N_PWR2 26 | #define REPEAT 100 // Measure average time 27 | // #define DEBUG // Print the results of polynomial convolution 28 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-509/main.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "include/params.h" 6 | 7 | 8 | // Include local CUDA header files. 9 | #include "include/cuda_kernel.cuh" 10 | 11 | 12 | int main(int argc, char** argv) 13 | { 14 | uint8_t mode= 0; 15 | uint16_t *h_m, *h_r; 16 | uint8_t *h_c, *h_pk, *h_sk, *h_rm; 17 | 18 | cudaMallocHost((void**) &h_pk, BATCH*NTRU_PUBLICKEYBYTES* sizeof(uint8_t)); 19 | cudaMallocHost((void**) &h_c, BATCH*NTRU_CIPHERTEXTBYTES * sizeof(uint8_t)); 20 | cudaMallocHost((void**) &h_sk, BATCH*NTRU_SECRETKEYBYTES * sizeof(uint8_t)); 21 | cudaMallocHost((void**) &h_rm, BATCH*NTRU_OWCPA_MSGBYTES * sizeof(uint8_t)); 22 | cudaMallocHost((void**) &h_r, BATCH*NTRU_N * sizeof(uint16_t)); 23 | cudaMallocHost((void**) &h_m, BATCH*NTRU_N* sizeof(uint16_t)); 24 | 25 | for (int i = 1; i < argc;) { 26 | if (strcmp(argv[i], "-m") == 0) { 27 | mode = atoi(argv[i + 1]); 28 | i += 2; 29 | } 30 | else { 31 | return 0; 32 | } 33 | } 34 | 35 | ntru_enc(mode, h_m, h_r, h_pk, h_c); 36 | ntru_dec(mode, h_rm, h_c, h_sk, h_m); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/main.cu: -------------------------------------------------------------------------------- 1 | // Include C++ header files. 2 | // #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "include/params.h" 8 | 9 | 10 | // Include local CUDA header files. 11 | #include "include/cuda_kernel.cuh" 12 | 13 | 14 | int main(int argc, char** argv) 15 | { 16 | uint8_t mode= 0; 17 | uint16_t *h_m, *h_r; 18 | uint8_t *h_c, *h_pk, *h_sk, *h_rm; 19 | 20 | cudaMallocHost((void**) &h_pk, BATCH*NTRU_PUBLICKEYBYTES* sizeof(uint8_t)); 21 | cudaMallocHost((void**) &h_r, BATCH*NTRU_N * sizeof(uint16_t)); 22 | cudaMallocHost((void**) &h_m, BATCH*NTRU_N* sizeof(uint16_t)); 23 | cudaMallocHost((void**) &h_c, BATCH*NTRU_CIPHERTEXTBYTES * sizeof(uint8_t)); 24 | cudaMallocHost((void**) &h_sk, BATCH*NTRU_SECRETKEYBYTES * sizeof(uint8_t)); 25 | cudaMallocHost((void**) &h_rm, BATCH*NTRU_OWCPA_MSGBYTES * sizeof(uint8_t)); 26 | 27 | for (int i = 1; i < argc;) { 28 | if (strcmp(argv[i], "-m") == 0) { 29 | mode = atoi(argv[i + 1]); 30 | i += 2; 31 | } 32 | else { 33 | return 0; 34 | } 35 | } 36 | 37 | ntru_enc(mode, h_m, h_r, h_pk, h_c); 38 | ntru_dec(mode, h_rm, h_c, h_sk, h_m); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-509/include/params.h: -------------------------------------------------------------------------------- 1 | #ifndef PARAMS_H 2 | #define PARAMS_H 3 | 4 | #define NTRU_HPS 5 | #define NTRU_N 509 6 | #define NTRU_LOGQ 11 7 | 8 | #ifndef CRYPTO_NAMESPACE 9 | #define CRYPTO_NAMESPACE(s) s 10 | #endif 11 | 12 | /* Do not modify below this line */ 13 | 14 | #define PAD32(X) ((((X) + 31)/32)*32) 15 | 16 | #define NTRU_Q (1 << NTRU_LOGQ) 17 | #define NTRU_WEIGHT (NTRU_Q/8 - 2) 18 | 19 | #define NTRU_SEEDBYTES 32 20 | #define NTRU_PRFKEYBYTES 32 21 | #define NTRU_SHAREDKEYBYTES 32 22 | 23 | #define NTRU_SAMPLE_IID_BYTES (NTRU_N-1) 24 | #define NTRU_SAMPLE_FT_BYTES ((30*(NTRU_N-1)+7)/8) 25 | #define NTRU_SAMPLE_FG_BYTES (NTRU_SAMPLE_IID_BYTES+NTRU_SAMPLE_FT_BYTES) 26 | #define NTRU_SAMPLE_RM_BYTES (NTRU_SAMPLE_IID_BYTES+NTRU_SAMPLE_FT_BYTES) 27 | 28 | #define NTRU_PACK_DEG (NTRU_N-1) 29 | #define NTRU_PACK_TRINARY_BYTES ((NTRU_PACK_DEG+4)/5) 30 | 31 | #define NTRU_OWCPA_MSGBYTES (2*NTRU_PACK_TRINARY_BYTES) 32 | #define NTRU_OWCPA_PUBLICKEYBYTES ((NTRU_LOGQ*NTRU_PACK_DEG+7)/8) 33 | #define NTRU_OWCPA_SECRETKEYBYTES (2*NTRU_PACK_TRINARY_BYTES + NTRU_OWCPA_PUBLICKEYBYTES) 34 | #define NTRU_OWCPA_BYTES ((NTRU_LOGQ*NTRU_PACK_DEG+7)/8) 35 | 36 | #define NTRU_PUBLICKEYBYTES (NTRU_OWCPA_PUBLICKEYBYTES) 37 | #define NTRU_SECRETKEYBYTES (NTRU_OWCPA_SECRETKEYBYTES + NTRU_PRFKEYBYTES) 38 | #define NTRU_CIPHERTEXTBYTES (NTRU_OWCPA_BYTES) 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/include/params.h: -------------------------------------------------------------------------------- 1 | #ifndef PARAMS_H 2 | #define PARAMS_H 3 | 4 | #define NTRU_HPS 5 | #define NTRU_N 677 6 | #define NTRU_LOGQ 11 7 | 8 | #ifndef CRYPTO_NAMESPACE 9 | #define CRYPTO_NAMESPACE(s) s 10 | #endif 11 | 12 | /* Do not modify below this line */ 13 | 14 | #define PAD32(X) ((((X) + 31)/32)*32) 15 | 16 | #define NTRU_Q (1 << NTRU_LOGQ) 17 | #define NTRU_WEIGHT (NTRU_Q/8 - 2) 18 | 19 | #define NTRU_SEEDBYTES 32 20 | #define NTRU_PRFKEYBYTES 32 21 | #define NTRU_SHAREDKEYBYTES 32 22 | 23 | #define NTRU_SAMPLE_IID_BYTES (NTRU_N-1) 24 | #define NTRU_SAMPLE_FT_BYTES ((30*(NTRU_N-1)+7)/8) 25 | #define NTRU_SAMPLE_FG_BYTES (NTRU_SAMPLE_IID_BYTES+NTRU_SAMPLE_FT_BYTES) 26 | #define NTRU_SAMPLE_RM_BYTES (NTRU_SAMPLE_IID_BYTES+NTRU_SAMPLE_FT_BYTES) 27 | 28 | #define NTRU_PACK_DEG (NTRU_N-1) 29 | #define NTRU_PACK_TRINARY_BYTES ((NTRU_PACK_DEG+4)/5) 30 | 31 | #define NTRU_OWCPA_MSGBYTES (2*NTRU_PACK_TRINARY_BYTES) 32 | #define NTRU_OWCPA_PUBLICKEYBYTES ((NTRU_LOGQ*NTRU_PACK_DEG+7)/8) 33 | #define NTRU_OWCPA_SECRETKEYBYTES (2*NTRU_PACK_TRINARY_BYTES + NTRU_OWCPA_PUBLICKEYBYTES) 34 | #define NTRU_OWCPA_BYTES ((NTRU_LOGQ*NTRU_PACK_DEG+7)/8) 35 | 36 | #define NTRU_PUBLICKEYBYTES (NTRU_OWCPA_PUBLICKEYBYTES) 37 | #define NTRU_SECRETKEYBYTES (NTRU_OWCPA_SECRETKEYBYTES + NTRU_PRFKEYBYTES) 38 | #define NTRU_CIPHERTEXTBYTES (NTRU_OWCPA_BYTES) 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-509/include/poly.cuh: -------------------------------------------------------------------------------- 1 | #include "../include/params.h" 2 | #include "../include/packq.cuh" 3 | #include 4 | #include 5 | // The only dimensions currently supported by WMMA (16x16) 6 | const int WMMA_M = 16; 7 | #define PAD NTRU_N%16 8 | #define WMMA_THREAD 32 9 | 10 | __global__ void poly_Rq_mul_gpu(uint16_t *r, uint16_t *a, uint16_t *b); 11 | __global__ void poly_Rq_mul_gpu_shared(uint16_t *r, uint16_t *g_a, uint16_t *g_b); 12 | __global__ void poly_Rq_mul_add_gpu(uint16_t *r, uint16_t *a, uint16_t *b, uint16_t *m); 13 | __global__ void poly_add(uint16_t *r, uint16_t *m); 14 | __global__ void poly_sub(uint16_t *c, uint16_t *d); 15 | __global__ void poly_lift(uint16_t *r, const uint16_t *a); 16 | 17 | __global__ void wmma_ker_padding(half *a, half *b, float *c); 18 | // Cyclic copy 19 | __global__ void convertU16ToFp16Negatecyclic(half *out, uint16_t *in) ; 20 | __global__ void convertU16ToFp16Negate(half *out, uint16_t *in); 21 | __global__ void convertU16ToFp16cyclic(half *out, uint16_t *in); 22 | __global__ void convertU16ToFp16(half *out, uint16_t *in); 23 | __global__ void convertFp32ToU16mod2048 (uint16_t *out, float *in) ; 24 | __global__ void remaining_gpu(uint16_t *r, uint16_t *a, uint16_t *b); 25 | __global__ void remaining_gpu2(uint16_t *r, uint16_t *a, uint16_t *b); 26 | __global__ void poly_Z3_to_Zq_gpu(uint16_t *r); 27 | __global__ void poly_Rq_to_S3_gpu(uint16_t *r, uint16_t *a); 28 | __global__ void poly_mod_3_Phi_n_gpu(uint16_t *r); 29 | __global__ void poly_mod_q_Phi_n_gpu(uint16_t *r); 30 | __global__ void poly_trinary_Zq_to_Z3_gpu(uint16_t *r); -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/include/poly.cuh: -------------------------------------------------------------------------------- 1 | #include "../include/params.h" 2 | #include "../include/packq.cuh" 3 | #include 4 | #include 5 | // The only dimensions currently supported by WMMA (16x16) 6 | const int WMMA_M = 16; 7 | #define PAD NTRU_N%16 8 | #define WMMA_THREAD 32 9 | 10 | __global__ void poly_Rq_mul_gpu(uint16_t *r, uint16_t *a, uint16_t *b); 11 | __global__ void poly_Rq_mul_gpu_shared(uint16_t *r, uint16_t *g_a, uint16_t *g_b); 12 | __global__ void poly_Rq_mul_add_gpu(uint16_t *r, uint16_t *a, uint16_t *b, uint16_t *m); 13 | __global__ void poly_add(uint16_t *r, uint16_t *m); 14 | __global__ void poly_sub(uint16_t *c, uint16_t *d); 15 | __global__ void poly_lift(uint16_t *r, const uint16_t *a); 16 | 17 | __global__ void wmma_ker_padding(half *a, half *b, float *c); 18 | // Cyclic copy 19 | __global__ void convertU16ToFp16Negatecyclic(half *out, uint16_t *in) ; 20 | __global__ void convertU16ToFp16Negate(half *out, uint16_t *in); 21 | __global__ void convertU16ToFp16cyclic(half *out, uint16_t *in); 22 | __global__ void convertU16ToFp16(half *out, uint16_t *in); 23 | __global__ void convertFp32ToU16mod2048 (uint16_t *out, float *in) ; 24 | __global__ void remaining_gpu(uint16_t *r, uint16_t *a, uint16_t *b); 25 | __global__ void remaining_gpu2(uint16_t *r, uint16_t *a, uint16_t *b); 26 | __global__ void poly_Z3_to_Zq_gpu(uint16_t *r); 27 | __global__ void poly_Rq_to_S3_gpu(uint16_t *r, uint16_t *a); 28 | __global__ void poly_mod_3_Phi_n_gpu(uint16_t *r); 29 | __global__ void poly_mod_q_Phi_n_gpu(uint16_t *r); 30 | __global__ void poly_trinary_Zq_to_Z3_gpu(uint16_t *r); -------------------------------------------------------------------------------- /TensorLAC/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1993-2017, NVIDIA CORPORATION. All rights reserved. 2 | # 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions 5 | # are met: 6 | # * Redistributions of source code must retain the above copyright 7 | # notice, this list of conditions and the following disclaimer. 8 | # * Redistributions in binary form must reproduce the above copyright 9 | # notice, this list of conditions and the following disclaimer in the 10 | # documentation and/or other materials provided with the distribution. 11 | # * Neither the name of NVIDIA CORPORATION nor the names of its 12 | # contributors may be used to endorse or promote products derived 13 | # from this software without specific prior written permission. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 16 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 19 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 23 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | 28 | all: TensorLAC.cu 29 | nvcc -o TensorLAC -arch=sm_75 TensorLAC.cu 30 | 31 | clean: 32 | rm -f TensorLAC 33 | 34 | 35 | -------------------------------------------------------------------------------- /TensorFro/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright (c) 1993-2017, NVIDIA CORPORATION. All rights reserved. 2 | # 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions 5 | # are met: 6 | # * Redistributions of source code must retain the above copyright 7 | # notice, this list of conditions and the following disclaimer. 8 | # * Redistributions in binary form must reproduce the above copyright 9 | # notice, this list of conditions and the following disclaimer in the 10 | # documentation and/or other materials provided with the distribution. 11 | # * Neither the name of NVIDIA CORPORATION nor the names of its 12 | # contributors may be used to endorse or promote products derived 13 | # from this software without specific prior written permission. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 16 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 19 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 23 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | 28 | all: TensorFro.cu 29 | # nvcc -o TensorFro -arch=sm_86 TensorFro.cu 30 | nvcc -o TensorFro -arch=sm_75 TensorFro.cu 31 | 32 | clean: 33 | rm -f TensorFro 34 | 35 | 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TensorCrypto 2 | This is the code accompanying the paper "TensorCrypto". 3 | https://eprint.iacr.org/2021/173 4 | 5 | # Introduction 6 | The tensor cores in NVIDIA GPU are exploited to perform polynomial convolution/matrix multiplication found in several lattice-based cryptosystems. In this paper, we demonsrate three successful cases: TensorTRU (NTRU), TensorLAC (LAC) and TensorFro (Frodo). It can benefit other similar lattice-based schemes that cannot be accelerated by NTT. This repository also contain source codes for implementing two parameter sets of NTRU public-key encryption, using the proposed tensor-core-based polynomial convolution. 7 | 8 | # How to use 9 | There is a Makefile accompanied with the source codes in each separate folder. You can build the executable by typing "make". 10 | 11 | Note that you need to change the sm version in GPU to suit your device. The default is -arch=sm_75, which is suitable for RTX2060,RTX2070 and RTX2080. 12 | 13 | 1) The NTRU public-key encryption (see NTRU-GPU-509 and NTRU-GPU-677) is implemented using ordinary GPU cores and tensor cores. You can select them by passing 0 or 1 to the executable. 14 | 15 | For instance, this executes NTRU with ordinary GPU cores: 16 | 17 | $ ./runtest -m 0 18 | 19 | This executes NTRU with ordinary tensor cores: 20 | 21 | $ ./runtest -m 1 22 | 23 | 2) The folder TensorTRU contains only the polynomial convolution with NTRU parameter sets. The flag NTRUHPS2048509 and NTRUHPS2048677 are used to select the respective NTRU parameter sets. You may also comment out the ENCRYPT flag for NTRU decryption. The flag K determines how many times we reuse the same public/private key pair. This allows a flexible configuration to cater for ephemeral key pair usage. The flag WMMA_THREAD determines how many threads per block for the tensor core. It can be set as any multiple of 32. 24 | 3) Similarly, the folders TensorLAC and TensorFro contains the code for executing polynomial convolution with different LAC and FrodoKEM parameter sets. 25 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/Makefile: -------------------------------------------------------------------------------- 1 | ########################################################### 2 | 3 | ## USER SPECIFIC DIRECTORIES ## 4 | 5 | # CUDA directory: 6 | CUDA_ROOT_DIR=/usr/local/cuda 7 | 8 | ########################################################## 9 | 10 | ## CC COMPILER OPTIONS ## 11 | 12 | # CC compiler options: 13 | CC=nvcc 14 | CC_FLAGS= 15 | CC_LIBS= 16 | 17 | ########################################################## 18 | 19 | ## NVCC COMPILER OPTIONS ## 20 | 21 | # NVCC compiler options: 22 | NVCC=nvcc 23 | # NVCC_FLAGS=-arch=sm_86 -gencode=arch=compute_86,code=sm_86 24 | NVCC_FLAGS=-arch=sm_75 -gencode=arch=compute_75,code=sm_75 25 | NVCC_LIBS= 26 | 27 | # CUDA library directory: 28 | CUDA_LIB_DIR= -L$(CUDA_ROOT_DIR)/lib64 29 | # CUDA include directory: 30 | CUDA_INC_DIR= -I$(CUDA_ROOT_DIR)/include 31 | # CUDA linking libraries: 32 | CUDA_LINK_LIBS= -lcudart 33 | 34 | ########################################################## 35 | 36 | ## Project file structure ## 37 | 38 | # Source file directory: 39 | SRC_DIR = src 40 | 41 | # Object file directory: 42 | OBJ_DIR = bin 43 | 44 | # Include header file diretory: 45 | INC_DIR = include 46 | 47 | ########################################################## 48 | 49 | ## Make variables ## 50 | 51 | # Target executable name: 52 | EXE = run_test 53 | 54 | # Object files: 55 | OBJS = $(OBJ_DIR)/main.o $(OBJ_DIR)/packq.o $(OBJ_DIR)/cuda_kernel.o $(OBJ_DIR)/poly.o $(OBJ_DIR)/check.o 56 | 57 | ########################################################## 58 | 59 | ## Compile ## 60 | 61 | # Link c++ and CUDA compiled object files to target executable: 62 | $(EXE) : $(OBJS) 63 | $(CC) $(CC_FLAGS) $(OBJS) -o $@ $(CUDA_INC_DIR) $(CUDA_LIB_DIR) $(CUDA_LINK_LIBS) 64 | 65 | # Compile main.cu file to object files: 66 | $(OBJ_DIR)/%.o : %.cu 67 | $(CC) $(CC_FLAGS) -c $< -o $@ 68 | # Compile main .c file to object files: 69 | 70 | # Compile C source files to object files: 71 | $(OBJ_DIR)/%.o : $(SRC_DIR)/%.c include/%.h 72 | $(CC) $(CC_FLAGS) -c $< -o $@ 73 | 74 | # Compile CUDA source files to object files: 75 | $(OBJ_DIR)/%.o : $(SRC_DIR)/%.cu $(INC_DIR)/%.cuh 76 | $(NVCC) $(NVCC_FLAGS) -c $< -o $@ $(NVCC_LIBS) 77 | 78 | # Clean objects in object directory. 79 | clean: 80 | $(RM) bin/* *.o $(EXE) 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-509/Makefile: -------------------------------------------------------------------------------- 1 | ########################################################### 2 | 3 | ## USER SPECIFIC DIRECTORIES ## 4 | 5 | # CUDA directory: 6 | CUDA_ROOT_DIR=/usr/local/cuda 7 | 8 | ########################################################## 9 | 10 | ## CC COMPILER OPTIONS ## 11 | 12 | # CC compiler options: 13 | CC=nvcc 14 | CC_FLAGS= 15 | CC_LIBS= 16 | 17 | ########################################################## 18 | 19 | ## NVCC COMPILER OPTIONS ## 20 | 21 | # NVCC compiler options: 22 | NVCC=nvcc 23 | #sm_86 ==> RTX3080, sm_86 ==> RTX2080 24 | # NVCC_FLAGS=-arch=sm_86 -gencode=arch=compute_86,code=sm_86 25 | NVCC_FLAGS=-arch=sm_75 -gencode=arch=compute_75,code=sm_75 26 | NVCC_LIBS= 27 | 28 | # CUDA library directory: 29 | CUDA_LIB_DIR= -L$(CUDA_ROOT_DIR)/lib64 30 | # CUDA include directory: 31 | CUDA_INC_DIR= -I$(CUDA_ROOT_DIR)/include 32 | # CUDA linking libraries: 33 | CUDA_LINK_LIBS= -lcudart 34 | 35 | ########################################################## 36 | 37 | ## Project file structure ## 38 | 39 | # Source file directory: 40 | SRC_DIR = src 41 | 42 | # Object file directory: 43 | OBJ_DIR = bin 44 | 45 | # Include header file diretory: 46 | INC_DIR = include 47 | 48 | ########################################################## 49 | 50 | ## Make variables ## 51 | 52 | # Target executable name: 53 | EXE = run_test 54 | 55 | # Object files: 56 | OBJS = $(OBJ_DIR)/main.o $(OBJ_DIR)/packq.o $(OBJ_DIR)/cuda_kernel.o $(OBJ_DIR)/poly.o $(OBJ_DIR)/check.o 57 | 58 | ########################################################## 59 | 60 | ## Compile ## 61 | 62 | # Link c++ and CUDA compiled object files to target executable: 63 | $(EXE) : $(OBJS) 64 | $(CC) $(CC_FLAGS) $(OBJS) -o $@ $(CUDA_INC_DIR) $(CUDA_LIB_DIR) $(CUDA_LINK_LIBS) 65 | 66 | # Compile main.cu file to object files: 67 | $(OBJ_DIR)/%.o : %.cu 68 | $(CC) $(CC_FLAGS) -c $< -o $@ 69 | # Compile main .c file to object files: 70 | 71 | # Compile C source files to object files: 72 | $(OBJ_DIR)/%.o : $(SRC_DIR)/%.c include/%.h 73 | $(CC) $(CC_FLAGS) -c $< -o $@ 74 | 75 | # Compile CUDA source files to object files: 76 | $(OBJ_DIR)/%.o : $(SRC_DIR)/%.cu $(INC_DIR)/%.cuh 77 | $(NVCC) $(NVCC_FLAGS) -c $< -o $@ $(NVCC_LIBS) 78 | 79 | # Clean objects in object directory. 80 | clean: 81 | $(RM) bin/* *.o $(EXE) 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-509/src/check.cu: -------------------------------------------------------------------------------- 1 | #include "../include/check.cuh" 2 | 3 | #include 4 | 5 | __global__ void owcpa_check_ciphertext_gpu(int *fail, uint8_t *ciphertext) 6 | { 7 | /* A ciphertext is log2(q)*(n-1) bits packed into bytes. */ 8 | /* Check that any unused bits of the final byte are zero. */ 9 | 10 | uint16_t t = 0; 11 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 12 | 13 | t = ciphertext[tid*NTRU_CIPHERTEXTBYTES + NTRU_CIPHERTEXTBYTES-1]; 14 | t &= 0xff << (8-(7 & (NTRU_LOGQ*NTRU_PACK_DEG))); 15 | 16 | /* We have 0 <= t < 256 */ 17 | /* Return 0 on success (t=0), 1 on failure */ 18 | // return (int) (1&((~t + 1) >> 15)); 19 | fail[bid] |= (int) (1&((~t + 1) >> 15)); 20 | } 21 | 22 | __global__ void owcpa_check_r_gpu(int *fail, uint16_t *r) 23 | { 24 | /* A valid r has coefficients in {0,1,q-1} and has r[N-1] = 0 */ 25 | /* Note: We may assume that 0 <= r[i] <= q-1 for all i */ 26 | 27 | int i; 28 | uint32_t t = 0; 29 | uint32_t bid = blockIdx.x; 30 | uint16_t c; 31 | for(i=0; i> 31)); 42 | fail[bid] |= (int) (1&((~t + 1) >> 31)); 43 | } 44 | 45 | __global__ void owcpa_check_m_gpu(int *fail, uint16_t *m) 46 | { 47 | /* Check that m is in message space, i.e. */ 48 | /* (1) |{i : m[i] = 1}| = |{i : m[i] = 2}|, and */ 49 | /* (2) |{i : m[i] != 0}| = NTRU_WEIGHT. */ 50 | /* Note: We may assume that m has coefficients in {0,1,2}. */ 51 | uint32_t bid = blockIdx.x; 52 | int i; 53 | uint32_t t = 0; 54 | uint16_t ps = 0; 55 | uint16_t ms = 0; 56 | for(i=0; i> 1); /* 0 if (1) holds */ 62 | t |= ms ^ NTRU_WEIGHT; /* 0 if (1) and (2) hold */ 63 | 64 | /* We have 0 <= t < 2^16. */ 65 | /* Return 0 on success (t=0), 1 on failure */ 66 | // return (int) (1&((~t + 1) >> 31)); 67 | fail[bid] |= (int) (1&((~t + 1) >> 31)); 68 | } 69 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/src/check.cu: -------------------------------------------------------------------------------- 1 | #include "../include/check.cuh" 2 | 3 | #include 4 | 5 | __global__ void owcpa_check_ciphertext_gpu(int *fail, uint8_t *ciphertext) 6 | { 7 | /* A ciphertext is log2(q)*(n-1) bits packed into bytes. */ 8 | /* Check that any unused bits of the final byte are zero. */ 9 | 10 | uint16_t t = 0; 11 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 12 | 13 | t = ciphertext[tid*NTRU_CIPHERTEXTBYTES + NTRU_CIPHERTEXTBYTES-1]; 14 | t &= 0xff << (8-(7 & (NTRU_LOGQ*NTRU_PACK_DEG))); 15 | 16 | /* We have 0 <= t < 256 */ 17 | /* Return 0 on success (t=0), 1 on failure */ 18 | // return (int) (1&((~t + 1) >> 15)); 19 | fail[bid] |= (int) (1&((~t + 1) >> 15)); 20 | } 21 | 22 | __global__ void owcpa_check_r_gpu(int *fail, uint16_t *r) 23 | { 24 | /* A valid r has coefficients in {0,1,q-1} and has r[N-1] = 0 */ 25 | /* Note: We may assume that 0 <= r[i] <= q-1 for all i */ 26 | 27 | int i; 28 | uint32_t t = 0; 29 | uint32_t bid = blockIdx.x; 30 | uint16_t c; 31 | for(i=0; i> 31)); 42 | fail[bid] |= (int) (1&((~t + 1) >> 31)); 43 | } 44 | 45 | __global__ void owcpa_check_m_gpu(int *fail, uint16_t *m) 46 | { 47 | /* Check that m is in message space, i.e. */ 48 | /* (1) |{i : m[i] = 1}| = |{i : m[i] = 2}|, and */ 49 | /* (2) |{i : m[i] != 0}| = NTRU_WEIGHT. */ 50 | /* Note: We may assume that m has coefficients in {0,1,2}. */ 51 | uint32_t bid = blockIdx.x; 52 | int i; 53 | uint32_t t = 0; 54 | uint16_t ps = 0; 55 | uint16_t ms = 0; 56 | for(i=0; i> 1); /* 0 if (1) holds */ 62 | t |= ms ^ NTRU_WEIGHT; /* 0 if (1) and (2) hold */ 63 | 64 | /* We have 0 <= t < 2^16. */ 65 | /* Return 0 on success (t=0), 1 on failure */ 66 | // return (int) (1&((~t + 1) >> 31)); 67 | fail[bid] |= (int) (1&((~t + 1) >> 31)); 68 | } 69 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-509/src/poly.cu: -------------------------------------------------------------------------------- 1 | 2 | #include "../include/poly.cuh" 3 | 4 | #include 5 | using namespace nvcuda; 6 | 7 | // Must be multiples of 16 for wmma code to work 8 | #define MODN(X) ((X) & (NTRU_N-1)) 9 | 10 | __device__ int mod(int a, int b) 11 | { 12 | int r = a % b; 13 | return r < 0 ? r + b : r; 14 | } 15 | 16 | __device__ uint16_t mod3_gpu(uint16_t a) 17 | { 18 | uint16_t r; 19 | int16_t t, c; 20 | 21 | r = (a >> 8) + (a & 0xff); // r mod 255 == a mod 255 22 | r = (r >> 4) + (r & 0xf); // r' mod 15 == r mod 15 23 | r = (r >> 2) + (r & 0x3); // r' mod 3 == r mod 3 24 | r = (r >> 2) + (r & 0x3); // r' mod 3 == r mod 3 25 | 26 | t = r - 3; 27 | c = t >> 15; 28 | 29 | return (c&r) ^ (~c&t); 30 | } 31 | 32 | __global__ void poly_Rq_mul_gpu(uint16_t *r, uint16_t *a, uint16_t *b) 33 | { 34 | uint32_t i, sum; 35 | uint32_t tidx = threadIdx.x, bidx = blockIdx.x; 36 | 37 | sum = 0;// use register to accumulate 38 | for(i=1; i>1)) & (NTRU_Q-1)); 85 | } 86 | 87 | __global__ void poly_add(uint16_t *r, uint16_t *m) 88 | { 89 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 90 | r[bid*NTRU_N + tid] = r[bid*NTRU_N + tid] + m[bid*NTRU_N + tid] ; 91 | r[bid*NTRU_N + tid] =MODQ(r[bid*NTRU_N + tid] ) ; 92 | } 93 | __global__ void poly_sub(uint16_t *c, uint16_t *d) 94 | { 95 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 96 | c[bid*NTRU_N + tid] = c[bid*NTRU_N + tid] - d[bid*NTRU_N + tid] ; 97 | // c[bid*NTRU_N + tid] =MODQ(c[bid*NTRU_N + tid] ) ; 98 | } 99 | 100 | __global__ void wmma_ker_padding(half *a, half *b, float *c) { 101 | // Declare the fragments 102 | wmma::fragment a_frag; 103 | // wklee, Read a in row major and b in column major 104 | wmma::fragment b_frag; 105 | wmma::fragment c_frag; 106 | 107 | // Each warp compute 16 elements along index i 108 | uint32_t warpID = (blockIdx.x * blockDim.x + threadIdx.x) / 32; 109 | uint32_t ldA_offset, ldB_offset, row_idx, col_idx, st_offset; 110 | row_idx = warpID%((NTRU_N_PWR2)/WMMA_M)*WMMA_M; 111 | col_idx = warpID/((NTRU_N_PWR2)/WMMA_M)*WMMA_M; 112 | st_offset = row_idx + col_idx * NTRU_N_PWR2 ; 113 | // Initialize the output to zero 114 | wmma::fill_fragment(c_frag, 0.0f); 115 | for (int i = 0; i < (NTRU_N_PWR2)/WMMA_M; i ++) 116 | { 117 | ldA_offset = row_idx*(NTRU_N_PWR2) + i*WMMA_M; 118 | ldB_offset = col_idx*(NTRU_N_PWR2) + i*WMMA_M; 119 | 120 | wmma::load_matrix_sync(a_frag, a + ldA_offset , NTRU_N_PWR2); 121 | wmma::load_matrix_sync(b_frag, b + ldB_offset , NTRU_N_PWR2); 122 | wmma::mma_sync(c_frag, a_frag, b_frag, c_frag); 123 | } 124 | 125 | wmma::store_matrix_sync(c + st_offset, c_frag, NTRU_N_PWR2, wmma::mem_col_major); 126 | } 127 | 128 | // Cyclic copy 129 | __global__ void convertU16ToFp16cyclic(half *out, uint16_t *in) { 130 | int tidx = threadIdx.x; 131 | int bidx = blockIdx.x; 132 | 133 | out[bidx + tidx * (NTRU_N_PWR2)] = in[mod(tidx - bidx, NTRU_N)]; 134 | } 135 | 136 | // Cyclic copy with negation 137 | __global__ void convertU16ToFp16Negatecyclic(half *out, uint16_t *in) { 138 | int tidx = threadIdx.x; 139 | int bidx = blockIdx.x; 140 | 141 | uint16_t temp = in[mod(tidx - bidx, NTRU_N)]; 142 | if(temp==2047) out[bidx + tidx * (NTRU_N_PWR2)] = -1; 143 | else out[bidx + tidx * (NTRU_N_PWR2)] = temp; 144 | 145 | } 146 | 147 | // Negate and copy 148 | __global__ void convertU16ToFp16Negate(half *out, uint16_t *in) { 149 | int tidx = threadIdx.x; 150 | int bidx = blockIdx.x; 151 | uint16_t temp = in[bidx*NTRU_N + tidx]; 152 | if(temp == 2047) out[bidx * (NTRU_N_PWR2) + tidx] = -1; 153 | else out[bidx * (NTRU_N_PWR2) + tidx] = temp; 154 | // out[bidx * NTRU_N + tidx] = 99; 155 | 156 | } 157 | 158 | // Direct copy 159 | __global__ void convertU16ToFp16(half *out, uint16_t *in) { 160 | int tidx = threadIdx.x; 161 | int bidx = blockIdx.x; 162 | 163 | out[bidx * (NTRU_N_PWR2) + tidx] = in[bidx * NTRU_N + tidx]; 164 | } 165 | 166 | // Straightforward copy 167 | __global__ void convertFp16ToU16 (uint16_t *out, half *in) { 168 | int tidx = threadIdx.x; 169 | int bidx = blockIdx.x; 170 | 171 | out[bidx * NTRU_N_PWR2 + tidx] = in[bidx * NTRU_N_PWR2 + tidx]; 172 | } 173 | 174 | // Convert and mod 175 | __global__ void convertFp32ToU16mod2048 (uint16_t *out, float *in) { 176 | int tidx = threadIdx.x; 177 | int bidx = blockIdx.x; 178 | int32_t tmp = (int32_t) in[bidx * (NTRU_N_PWR2) + tidx]; 179 | out[bidx * NTRU_N + tidx] = MODQ(tmp); 180 | } 181 | 182 | /* Map {0, 1, 2} -> {0,1,q-1} in place */ 183 | __global__ void poly_Z3_to_Zq_gpu(uint16_t *r) 184 | { 185 | uint32_t tid=threadIdx.x, bid=blockIdx.x; 186 | 187 | r[bid*NTRU_N+ tid] = r[bid*NTRU_N+ tid] | ((-(r[bid*NTRU_N+ tid]>>1)) & (NTRU_Q-1)); 188 | } 189 | 190 | __global__ void poly_Rq_to_S3_gpu(uint16_t *r, uint16_t *a) 191 | { 192 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 193 | uint16_t flag; 194 | 195 | /* The coefficients of a are stored as non-negative integers. */ 196 | /* We must translate to representatives in [-q/2, q/2) before */ 197 | /* reduction mod 3. */ 198 | /* Need an explicit reduction mod q here */ 199 | r[bid*NTRU_N + tid] = MODQ(a[bid*NTRU_N + tid]); 200 | __syncthreads(); 201 | /* flag = 1 if r[tid] >= q/2 else 0 */ 202 | flag = r[bid*NTRU_N + tid] >> (NTRU_LOGQ-1); 203 | __syncthreads(); 204 | /* Now we will add (-q) mod 3 if r[tid] >= q/2 */ 205 | /* Note (-q) mod 3=(-2^k) mod 3=1<<(1-(k&1)) */ 206 | r[bid*NTRU_N + tid] += flag << (1-(NTRU_LOGQ&1)); 207 | __syncthreads(); 208 | // poly_mod_3_Phi_n(r); 209 | r[bid*NTRU_N + tid] = mod3_gpu(r[bid*NTRU_N + tid] + 2*r[bid*NTRU_N + NTRU_N-1]); 210 | __syncthreads(); 211 | } 212 | 213 | __global__ void poly_mod_3_Phi_n_gpu(uint16_t *r) 214 | { 215 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 216 | // for(i=0; i {0,1,2} in place */ 228 | __global__ void poly_trinary_Zq_to_Z3_gpu(uint16_t *r) 229 | { 230 | uint32_t tid=threadIdx.x, bid=blockIdx.x; 231 | // for(i=0; i>(NTRU_LOGQ-1))); 235 | } 236 | } 237 | 238 | -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/src/poly.cu: -------------------------------------------------------------------------------- 1 | 2 | #include "../include/poly.cuh" 3 | 4 | #include 5 | using namespace nvcuda; 6 | 7 | // Must be multiples of 16 for wmma code to work 8 | #define MODN(X) ((X) & (NTRU_N-1)) 9 | 10 | __device__ int mod(int a, int b) 11 | { 12 | int r = a % b; 13 | return r < 0 ? r + b : r; 14 | } 15 | 16 | __device__ uint16_t mod3_gpu(uint16_t a) 17 | { 18 | uint16_t r; 19 | int16_t t, c; 20 | 21 | r = (a >> 8) + (a & 0xff); // r mod 255 == a mod 255 22 | r = (r >> 4) + (r & 0xf); // r' mod 15 == r mod 15 23 | r = (r >> 2) + (r & 0x3); // r' mod 3 == r mod 3 24 | r = (r >> 2) + (r & 0x3); // r' mod 3 == r mod 3 25 | 26 | t = r - 3; 27 | c = t >> 15; 28 | 29 | return (c&r) ^ (~c&t); 30 | } 31 | 32 | __global__ void poly_Rq_mul_gpu(uint16_t *r, uint16_t *a, uint16_t *b) 33 | { 34 | uint32_t i, sum; 35 | uint32_t tidx = threadIdx.x, bidx = blockIdx.x; 36 | 37 | sum = 0;// use register to accumulate 38 | for(i=1; i>1)) & (NTRU_Q-1)); 85 | } 86 | 87 | __global__ void poly_add(uint16_t *r, uint16_t *m) 88 | { 89 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 90 | r[bid*NTRU_N + tid] = r[bid*NTRU_N + tid] + m[bid*NTRU_N + tid] ; 91 | r[bid*NTRU_N + tid] =MODQ(r[bid*NTRU_N + tid] ) ; 92 | } 93 | __global__ void poly_sub(uint16_t *c, uint16_t *d) 94 | { 95 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 96 | c[bid*NTRU_N + tid] = c[bid*NTRU_N + tid] - d[bid*NTRU_N + tid] ; 97 | // c[bid*NTRU_N + tid] =MODQ(c[bid*NTRU_N + tid] ) ; 98 | } 99 | 100 | __global__ void wmma_ker_padding(half *a, half *b, float *c) { 101 | // Declare the fragments 102 | wmma::fragment a_frag; 103 | // wklee, Read a in row major and b in column major 104 | wmma::fragment b_frag; 105 | wmma::fragment c_frag; 106 | 107 | // Each warp compute 16 elements along index i 108 | uint32_t warpID = (blockIdx.x * blockDim.x + threadIdx.x) / 32; 109 | uint32_t ldA_offset, ldB_offset, row_idx, col_idx, st_offset; 110 | row_idx = warpID%((NTRU_N_PWR2)/WMMA_M)*WMMA_M; 111 | col_idx = warpID/((NTRU_N_PWR2)/WMMA_M)*WMMA_M; 112 | st_offset = row_idx + col_idx * NTRU_N_PWR2 ; 113 | // Initialize the output to zero 114 | wmma::fill_fragment(c_frag, 0.0f); 115 | for (int i = 0; i < (NTRU_N_PWR2)/WMMA_M; i ++) 116 | { 117 | ldA_offset = row_idx*(NTRU_N_PWR2) + i*WMMA_M; 118 | ldB_offset = col_idx*(NTRU_N_PWR2) + i*WMMA_M; 119 | 120 | wmma::load_matrix_sync(a_frag, a + ldA_offset , NTRU_N_PWR2); 121 | wmma::load_matrix_sync(b_frag, b + ldB_offset , NTRU_N_PWR2); 122 | wmma::mma_sync(c_frag, a_frag, b_frag, c_frag); 123 | } 124 | 125 | wmma::store_matrix_sync(c + st_offset, c_frag, NTRU_N_PWR2, wmma::mem_col_major); 126 | } 127 | 128 | // Cyclic copy 129 | __global__ void convertU16ToFp16cyclic(half *out, uint16_t *in) { 130 | int tidx = threadIdx.x; 131 | int bidx = blockIdx.x; 132 | 133 | out[bidx + tidx * (NTRU_N_PWR2)] = in[mod(tidx - bidx, NTRU_N)]; 134 | } 135 | 136 | // Cyclic copy with negation 137 | __global__ void convertU16ToFp16Negatecyclic(half *out, uint16_t *in) { 138 | int tidx = threadIdx.x; 139 | int bidx = blockIdx.x; 140 | 141 | uint16_t temp = in[mod(tidx - bidx, NTRU_N)]; 142 | if(temp==2047) out[bidx + tidx * (NTRU_N_PWR2)] = -1; 143 | else out[bidx + tidx * (NTRU_N_PWR2)] = temp; 144 | 145 | } 146 | 147 | // Negate and copy 148 | __global__ void convertU16ToFp16Negate(half *out, uint16_t *in) { 149 | int tidx = threadIdx.x; 150 | int bidx = blockIdx.x; 151 | uint16_t temp = in[bidx*NTRU_N + tidx]; 152 | if(temp == 2047) out[bidx * (NTRU_N_PWR2) + tidx] = -1; 153 | else out[bidx * (NTRU_N_PWR2) + tidx] = temp; 154 | // out[bidx * NTRU_N + tidx] = 99; 155 | 156 | } 157 | 158 | // Direct copy 159 | __global__ void convertU16ToFp16(half *out, uint16_t *in) { 160 | int tidx = threadIdx.x; 161 | int bidx = blockIdx.x; 162 | 163 | out[bidx * (NTRU_N_PWR2) + tidx] = in[bidx * NTRU_N + tidx]; 164 | } 165 | 166 | // Straightforward copy 167 | __global__ void convertFp16ToU16 (uint16_t *out, half *in) { 168 | int tidx = threadIdx.x; 169 | int bidx = blockIdx.x; 170 | 171 | out[bidx * NTRU_N_PWR2 + tidx] = in[bidx * NTRU_N_PWR2 + tidx]; 172 | } 173 | 174 | // Convert and mod 175 | __global__ void convertFp32ToU16mod2048 (uint16_t *out, float *in) { 176 | int tidx = threadIdx.x; 177 | int bidx = blockIdx.x; 178 | int32_t tmp = (int32_t) in[bidx * (NTRU_N_PWR2) + tidx]; 179 | out[bidx * NTRU_N + tidx] = MODQ(tmp); 180 | } 181 | 182 | /* Map {0, 1, 2} -> {0,1,q-1} in place */ 183 | __global__ void poly_Z3_to_Zq_gpu(uint16_t *r) 184 | { 185 | uint32_t tid=threadIdx.x, bid=blockIdx.x; 186 | 187 | r[bid*NTRU_N+ tid] = r[bid*NTRU_N+ tid] | ((-(r[bid*NTRU_N+ tid]>>1)) & (NTRU_Q-1)); 188 | } 189 | 190 | __global__ void poly_Rq_to_S3_gpu(uint16_t *r, uint16_t *a) 191 | { 192 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 193 | uint16_t flag; 194 | 195 | /* The coefficients of a are stored as non-negative integers. */ 196 | /* We must translate to representatives in [-q/2, q/2) before */ 197 | /* reduction mod 3. */ 198 | /* Need an explicit reduction mod q here */ 199 | r[bid*NTRU_N + tid] = MODQ(a[bid*NTRU_N + tid]); 200 | __syncthreads(); 201 | /* flag = 1 if r[tid] >= q/2 else 0 */ 202 | flag = r[bid*NTRU_N + tid] >> (NTRU_LOGQ-1); 203 | __syncthreads(); 204 | /* Now we will add (-q) mod 3 if r[tid] >= q/2 */ 205 | /* Note (-q) mod 3=(-2^k) mod 3=1<<(1-(k&1)) */ 206 | r[bid*NTRU_N + tid] += flag << (1-(NTRU_LOGQ&1)); 207 | __syncthreads(); 208 | // poly_mod_3_Phi_n(r); 209 | r[bid*NTRU_N + tid] = mod3_gpu(r[bid*NTRU_N + tid] + 2*r[bid*NTRU_N + NTRU_N-1]); 210 | __syncthreads(); 211 | } 212 | 213 | __global__ void poly_mod_3_Phi_n_gpu(uint16_t *r) 214 | { 215 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 216 | // for(i=0; i {0,1,2} in place */ 228 | __global__ void poly_trinary_Zq_to_Z3_gpu(uint16_t *r) 229 | { 230 | uint32_t tid=threadIdx.x, bid=blockIdx.x; 231 | // for(i=0; i>(NTRU_LOGQ-1))); 235 | } 236 | } 237 | 238 | -------------------------------------------------------------------------------- /TensorLAC/TensorLAC.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "params.h" 7 | using namespace nvcuda; 8 | 9 | #define BIG_Q 1024*LAC_Q//1024*Q 10 | #define MODQ(X) (X+BIG_Q)%LAC_Q 11 | #define MODN(X) ((X) & (LAC_N-1)) 12 | // The only dimensions currently supported by WMMA (16x16) 13 | const int WMMA_M = 16; 14 | 15 | // This is from the reference implementation 16 | __global__ void poly_mul_ref_gpu(const uint8_t *a, const uint8_t *s, uint8_t *b) 17 | { 18 | // __shared__ unsigned char v[LAC_N+LAC_N]; 19 | __shared__ unsigned char v[LAC_N+LAC_N]; 20 | int32_t sum, j; 21 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 22 | 23 | //construct matrix of a 24 | v[tid]=a[bid*LAC_N + LAC_N-1-tid]; 25 | v[tid+LAC_N]=LAC_Q-v[tid]; 26 | __syncthreads(); 27 | 28 | sum=0; 29 | for(j=0;j a_frag; 60 | // wklee, Read a in row major and b in column major 61 | wmma::fragment b_frag; 62 | wmma::fragment c_frag; 63 | 64 | // Each warp compute 16 elements along index i 65 | uint32_t warpID = (blockIdx.x * blockDim.x + threadIdx.x) / 32; 66 | uint32_t ldA_offset, ldB_offset, row_idx, col_idx, st_offset; 67 | row_idx = warpID%((LAC_N)/WMMA_M)*WMMA_M; 68 | col_idx = warpID/((LAC_N)/WMMA_M)*WMMA_M; 69 | st_offset = row_idx + col_idx * LAC_N ; 70 | // Initialize the output to zero 71 | wmma::fill_fragment(c_frag, 0.0f); 72 | for (int i = 0; i < (LAC_N)/WMMA_M; i ++) 73 | { 74 | ldA_offset = row_idx*(LAC_N) + i*WMMA_M; 75 | ldB_offset = col_idx*(LAC_N) + i*WMMA_M; 76 | 77 | wmma::load_matrix_sync(a_frag, a + ldA_offset , LAC_N); 78 | wmma::load_matrix_sync(b_frag, b + ldB_offset , LAC_N); 79 | wmma::mma_sync(c_frag, a_frag, b_frag, c_frag); 80 | } 81 | 82 | wmma::store_matrix_sync(c + st_offset, c_frag, LAC_N, wmma::mem_col_major); 83 | } 84 | 85 | __device__ int mod(int a, int b) 86 | { 87 | int r = a % b; 88 | return r < 0 ? r + b : r; 89 | } 90 | 91 | __global__ void convertU8ToU8cyclic(uint8_t *out, uint8_t *in) { 92 | int tidx = threadIdx.x; 93 | int bidx = blockIdx.x; 94 | 95 | if(tidx - bidx<0) 96 | out[bidx + tidx * LAC_N] = LAC_Q-in[mod(tidx - bidx, LAC_N)]; 97 | else 98 | out[bidx + tidx * (LAC_N)] = in[mod(tidx - bidx, LAC_N)]; 99 | } 100 | 101 | // Convert and mod 102 | __global__ void convertINT32ToU8modQ (uint8_t *out, int *in) { 103 | int tidx = threadIdx.x; 104 | int bidx = blockIdx.x; 105 | int32_t tmp = (int32_t) in[bidx * (LAC_N) + tidx]; 106 | tmp = MODQ(tmp); 107 | // if(tmp<0) tmp+=LAC_Q; 108 | out[bidx * LAC_N + tidx] = tmp; 109 | } 110 | 111 | 112 | 113 | int main(int argc, char* argv[]) { 114 | int *d_c_wmma_u8; 115 | uint32_t i, j; 116 | 117 | uint8_t *h_a, *h_s, *h_b, *h_b_gpu_u8; 118 | uint8_t *d_a_u8, *d_s_u8, *d_b_u8, *d_a_u8_cyclic, *d_c_u8; 119 | 120 | cudaEvent_t start, stop; 121 | float elapsed; 122 | 123 | cudaEventCreate(&start); 124 | cudaEventCreate(&stop); 125 | 126 | cudaMalloc((void**) &d_a_u8, LAC_N*LAC_N* sizeof(uint8_t)); 127 | cudaMalloc((void**) &d_s_u8, LAC_N*LAC_N* sizeof(uint8_t)); 128 | cudaMalloc((void**) &d_a_u8_cyclic, LAC_N*LAC_N* sizeof(uint8_t)); 129 | cudaMalloc((void**) &d_b_u8, LAC_N*LAC_N* sizeof(uint8_t)); 130 | cudaMalloc((void**) &d_c_u8, LAC_N*LAC_N* sizeof(uint8_t)); 131 | cudaMalloc((void**) &d_c_wmma_u8, LAC_N*LAC_N* sizeof(int)); 132 | 133 | cudaMallocHost((void**) &h_a, LAC_N*LAC_N* sizeof(uint8_t)); 134 | cudaMallocHost((void**) &h_s, LAC_N*LAC_N* sizeof(uint8_t)); 135 | cudaMallocHost((void**) &h_b, LAC_N*LAC_N* sizeof(uint8_t)); 136 | cudaMallocHost((void**) &h_b_gpu_u8, LAC_N*LAC_N* sizeof(uint8_t)); 137 | 138 | uint32_t t1 = LAC_N%WMMA_M, t2 = 0; 139 | if(t1!=0) t2=1; 140 | uint32_t threads = 32 * ((LAC_N+t2)/WMMA_M) * ((LAC_N+t2)/WMMA_M);// each warp computes 16x16 matrix 141 | uint32_t blocks = 1; 142 | if(threads>WMMA_THREAD) 143 | { 144 | blocks = threads / WMMA_THREAD; 145 | threads = WMMA_THREAD; 146 | } 147 | 148 | printf("\nM = %d, LAC_N= %u, blocks: %u threads: %u \n\n", LAC_N, LAC_N, blocks, threads); 149 | 150 | /* initialize random seed: */ 151 | srand (time(NULL)); // comment out this to yield a static poly elements. 152 | // This is for encryption 153 | for (i = 0; i >>(d_b_u8, d_a_u8, d_s_u8); 174 | // poly_mul_ref_gpu<<>>(d_a_u8, d_s_u8, d_b_u8); 175 | } 176 | cudaEventRecord(stop); 177 | cudaEventSynchronize(stop); 178 | cudaEventElapsedTime(&elapsed, start, stop); 179 | cudaMemcpy(h_b, d_b_u8, LAC_N * LAC_N * sizeof(uint8_t), cudaMemcpyHostToDevice); 180 | printf("gpu u32 took %f ms\n", elapsed/REPEAT); 181 | 182 | #ifdef DEBUG 183 | printf("gpu u16 result\n"); for (i = 0; i <2; i++) { 184 | printf("\nbatch: %u\n", i);for (j = 0; j >>(d_a_u8_cyclic, d_a_u8); 192 | wmma_ker_u8<<< blocks, threads >>> (d_a_u8_cyclic, d_s_u8, d_c_wmma_u8); 193 | convertINT32ToU8modQ<<>>(d_c_u8, d_c_wmma_u8); 194 | } 195 | cudaEventRecord(stop); 196 | cudaEventSynchronize(stop); 197 | 198 | cudaMemcpy(h_b_gpu_u8, d_c_u8, LAC_N * LAC_N * sizeof(uint8_t), cudaMemcpyDeviceToHost); 199 | float wmmaTime; 200 | cudaEventElapsedTime(&wmmaTime, start, stop); 201 | printf("gpu tensor core took %fms\n", wmmaTime/REPEAT); 202 | 203 | #ifdef DEBUG 204 | printf("gpu tensor core result\n"); for (int i = 0; i < 2; i++) { 205 | printf("batch: %u\n", i); 206 | for (j = 0; j 4 | 5 | __device__ void poly_Sq_frombytes_gpu(uint16_t *r, const unsigned char *a) 6 | { 7 | int i; 8 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 9 | uint32_t b_offset = bid*NTRU_N, a_offset = bid*NTRU_PUBLICKEYBYTES; 10 | 11 | r[b_offset + 8*tid+0] = (a[a_offset + 11*tid+ 0] >> 0) | (((uint16_t)a[a_offset + 11*tid+ 1] & 0x07) << 8); 12 | r[b_offset + 8*tid+1] = (a[a_offset + 11*tid+ 1] >> 3) | (((uint16_t)a[a_offset + 11*tid+ 2] & 0x3f) << 5); 13 | r[b_offset + 8*tid+2] = (a[a_offset + 11*tid+ 2] >> 6) | (((uint16_t)a[a_offset + 11*tid+ 3] & 0xff) << 2) | (((uint16_t)a[a_offset + 11*tid+ 4] & 0x01) << 10); 14 | r[b_offset + 8*tid+3] = (a[a_offset + 11*tid+ 4] >> 1) | (((uint16_t)a[a_offset + 11*tid+ 5] & 0x0f) << 7); 15 | r[b_offset + 8*tid+4] = (a[a_offset + 11*tid+ 5] >> 4) | (((uint16_t)a[a_offset + 11*tid+ 6] & 0x7f) << 4); 16 | r[b_offset + 8*tid+5] = (a[a_offset + 11*tid+ 6] >> 7) | (((uint16_t)a[a_offset + 11*tid+ 7] & 0xff) << 1) | (((uint16_t)a[a_offset + 11*tid+ 8] & 0x03) << 9); 17 | r[b_offset + 8*tid+6] = (a[a_offset + 11*tid+ 8] >> 2) | (((uint16_t)a[a_offset + 11*tid+ 9] & 0x1f) << 6); 18 | r[b_offset + 8*tid+7] = (a[a_offset + 11*tid+ 9] >> 5) | (((uint16_t)a[a_offset + 11*tid+10] & 0xff) << 3); 19 | 20 | if(tid==0) //wklee, can be parallelized later 21 | { 22 | i=63; 23 | switch(NTRU_PACK_DEG&0x07) 24 | { 25 | // cases 0 and 6 are impossible since 2 generates (Z/n)* and 26 | // p mod 8 in {1, 7} implies that 2 is a quadratic residue. 27 | case 4: 28 | r[b_offset + 8*i+0] = (a[a_offset + 11*i+ 0] >> 0) | (((uint16_t)a[a_offset + 11*i+ 1] & 0x07) << 8); 29 | r[b_offset + 8*i+1] = (a[a_offset + 11*i+ 1] >> 3) | (((uint16_t)a[a_offset + 11*i+ 2] & 0x3f) << 5); 30 | r[b_offset + 8*i+2] = (a[a_offset + 11*i+ 2] >> 6) | (((uint16_t)a[a_offset + 11*i+ 3] & 0xff) << 2) | (((uint16_t)a[a_offset + 11*i+ 4] & 0x01) << 10); 31 | r[b_offset + 8*i+3] = (a[a_offset + 11*i+ 4] >> 1) | (((uint16_t)a[a_offset + 11*i+ 5] & 0x0f) << 7); 32 | break; 33 | case 2: 34 | r[b_offset + 8*i+0] = (a[a_offset + 11*i+ 0] >> 0) | (((uint16_t)a[a_offset + 11*i+ 1] & 0x07) << 8); 35 | r[b_offset + 8*i+1] = (a[a_offset + 11*i+ 1] >> 3) | (((uint16_t)a[a_offset + 11*i+ 2] & 0x3f) << 5); 36 | break; 37 | } 38 | r[NTRU_N-1] = 0; 39 | } 40 | } 41 | 42 | __global__ void poly_Sq_tobytes_gpu(unsigned char *r, const uint16_t *a) 43 | { 44 | int i,j; 45 | uint16_t t[8]; 46 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 47 | uint32_t b_offset = bid*NTRU_CIPHERTEXTBYTES, a_offset = bid*NTRU_N; 48 | 49 | for(j=0;j<8;j++)// wklee, we can remove this, already MOD 50 | t[j] = MODQ(a[a_offset + 8*tid+j]); 51 | 52 | r[b_offset + 11 * tid + 0] = (unsigned char) ( t[0] & 0xff); 53 | r[b_offset + 11 * tid + 1] = (unsigned char) ((t[0] >> 8) | ((t[1] & 0x1f) << 3)); 54 | r[b_offset + 11 * tid + 2] = (unsigned char) ((t[1] >> 5) | ((t[2] & 0x03) << 6)); 55 | r[b_offset + 11 * tid + 3] = (unsigned char) ((t[2] >> 2) & 0xff); 56 | r[b_offset + 11 * tid + 4] = (unsigned char) ((t[2] >> 10) | ((t[3] & 0x7f) << 1)); 57 | r[b_offset + 11 * tid + 5] = (unsigned char) ((t[3] >> 7) | ((t[4] & 0x0f) << 4)); 58 | r[b_offset + 11 * tid + 6] = (unsigned char) ((t[4] >> 4) | ((t[5] & 0x01) << 7)); 59 | r[b_offset + 11 * tid + 7] = (unsigned char) ((t[5] >> 1) & 0xff); 60 | r[b_offset + 11 * tid + 8] = (unsigned char) ((t[5] >> 9) | ((t[6] & 0x3f) << 2)); 61 | r[b_offset + 11 * tid + 9] = (unsigned char) ((t[6] >> 6) | ((t[7] & 0x07) << 5)); 62 | r[b_offset + 11 * tid + 10] = (unsigned char) ((t[7] >> 3)); 63 | __syncthreads(); 64 | if(tid==0)//wklee, can be parallelized later 65 | { 66 | i = 63; 67 | // wklee, we can remove this, already MOD 68 | for(j=0;j> 8) | ((t[1] & 0x1f) << 3); 78 | r[b_offset + 11 * i + 2] = (unsigned char) (t[1] >> 5) | ((t[2] & 0x03) << 6); 79 | r[b_offset + 11 * i + 3] = (unsigned char) (t[2] >> 2) & 0xff; 80 | r[b_offset + 11 * i + 4] = (unsigned char) (t[2] >> 10) | ((t[3] & 0x7f) << 1); 81 | r[b_offset + 11 * i + 5] = (unsigned char) (t[3] >> 7) | ((t[4] & 0x0f) << 4); 82 | break; 83 | case 2: 84 | r[b_offset + 11 * i + 0] = (unsigned char) (t[0] & 0xff); 85 | r[b_offset + 11 * i + 1] = (unsigned char) (t[0] >> 8) | ((t[1] & 0x1f) << 3); 86 | r[b_offset + 11 * i + 2] = (unsigned char) (t[1] >> 5) | ((t[2] & 0x03) << 6); 87 | break; 88 | } 89 | } 90 | } 91 | 92 | 93 | __global__ void poly_Rq_sum_zero_frombytes_gpu(uint16_t *r, uint8_t *a) 94 | { 95 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 96 | uint32_t b_offset = bid*NTRU_N; 97 | int i; 98 | poly_Sq_frombytes_gpu(r,a); 99 | // __syncthreads(); 100 | // /* Set r[n-1] so that the sum of coefficients is zero mod q */ 101 | // if(tid==0) 102 | // { 103 | // // for(i=0;i> 8) + (a & 0xff); // r mod 255 == a mod 255 123 | r = (r >> 4) + (r & 0xf); // r' mod 15 == r mod 15 124 | r = (r >> 2) + (r & 0x3); // r' mod 3 == r mod 3 125 | r = (r >> 2) + (r & 0x3); // r' mod 3 == r mod 3 126 | 127 | t = r - 3; 128 | c = t >> 15; 129 | 130 | return (c&r) ^ (~c&t); 131 | } 132 | 133 | __global__ void poly_S3_frombytes_gpu(uint16_t *r, uint8_t* msg) 134 | { 135 | int i, j; 136 | uint8_t c; 137 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 138 | 139 | if(tid < NTRU_PACK_DEG/5) 140 | { 141 | c = msg[bid*NTRU_SECRETKEYBYTES + tid]; 142 | r[bid*NTRU_N + 5*tid+0] = c; 143 | r[bid*NTRU_N + 5*tid+1] = c * 171 >> 9; // this is division by 3 144 | r[bid*NTRU_N + 5*tid+2] = c * 57 >> 9; // division by 3^2 145 | r[bid*NTRU_N + 5*tid+3] = c * 19 >> 9; // division by 3^3 146 | r[bid*NTRU_N + 5*tid+4] = c * 203 >> 14; // etc. 147 | } 148 | if(tid==0) 149 | { 150 | i = NTRU_PACK_DEG/5; 151 | c = msg[bid*NTRU_SECRETKEYBYTES +i]; 152 | for(j=0; (5*i+j)> 9; 156 | } 157 | r[bid*NTRU_N +NTRU_N-1] = 0; 158 | } 159 | __syncthreads(); 160 | // poly_mod_3_Phi_n(r); 161 | // for(i=0; i (NTRU_PACK_DEG / 5) * 5 // if 5 does not divide NTRU_N-1 178 | 179 | if(tid==0) 180 | { 181 | i = NTRU_PACK_DEG/5; 182 | c = 0; 183 | for(j = NTRU_PACK_DEG - (5*i) - 1; j>=0; j--) 184 | c = (3*c + a[bid*NTRU_N + 5*i+j]) & 255; 185 | msg[bid*NTRU_OWCPA_MSGBYTES + i] = c; 186 | } 187 | #endif 188 | } 189 | 190 | 191 | __global__ void poly_Sq_frombytes_gpu_global(uint16_t *r, const unsigned char *a) 192 | { 193 | int i = NTRU_PACK_DEG/8; 194 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 195 | uint32_t b_offset = bid*NTRU_N, a_offset = bid*NTRU_SECRETKEYBYTES; 196 | 197 | r[b_offset + 8*tid+0] = (a[a_offset + 11*tid+ 0] >> 0) | (((uint16_t)a[a_offset + 11*tid+ 1] & 0x07) << 8); 198 | r[b_offset + 8*tid+1] = (a[a_offset + 11*tid+ 1] >> 3) | (((uint16_t)a[a_offset + 11*tid+ 2] & 0x3f) << 5); 199 | r[b_offset + 8*tid+2] = (a[a_offset + 11*tid+ 2] >> 6) | (((uint16_t)a[a_offset + 11*tid+ 3] & 0xff) << 2) | (((uint16_t)a[a_offset + 11*tid+ 4] & 0x01) << 10); 200 | r[b_offset + 8*tid+3] = (a[a_offset + 11*tid+ 4] >> 1) | (((uint16_t)a[a_offset + 11*tid+ 5] & 0x0f) << 7); 201 | r[b_offset + 8*tid+4] = (a[a_offset + 11*tid+ 5] >> 4) | (((uint16_t)a[a_offset + 11*tid+ 6] & 0x7f) << 4); 202 | r[b_offset + 8*tid+5] = (a[a_offset + 11*tid+ 6] >> 7) | (((uint16_t)a[a_offset + 11*tid+ 7] & 0xff) << 1) | (((uint16_t)a[a_offset + 11*tid+ 8] & 0x03) << 9); 203 | r[b_offset + 8*tid+6] = (a[a_offset + 11*tid+ 8] >> 2) | (((uint16_t)a[a_offset + 11*tid+ 9] & 0x1f) << 6); 204 | r[b_offset + 8*tid+7] = (a[a_offset + 11*tid+ 9] >> 5) | (((uint16_t)a[a_offset + 11*tid+10] & 0xff) << 3); 205 | 206 | if(tid==0) //wklee, can be parallelized later 207 | { 208 | switch(NTRU_PACK_DEG&0x07) 209 | { 210 | // cases 0 and 6 are impossible since 2 generates (Z/n)* and 211 | // p mod 8 in {1, 7} implies that 2 is a quadratic residue. 212 | case 4: 213 | r[b_offset + 8*i+0] = (a[a_offset + 11*i+ 0] >> 0) | (((uint16_t)a[a_offset + 11*i+ 1] & 0x07) << 8); 214 | r[b_offset + 8*i+1] = (a[a_offset + 11*i+ 1] >> 3) | (((uint16_t)a[a_offset + 11*i+ 2] & 0x3f) << 5); 215 | r[b_offset + 8*i+2] = (a[a_offset + 11*i+ 2] >> 6) | (((uint16_t)a[a_offset + 11*i+ 3] & 0xff) << 2) | (((uint16_t)a[a_offset + 11*i+ 4] & 0x01) << 10); 216 | r[b_offset + 8*i+3] = (a[a_offset + 11*i+ 4] >> 1) | (((uint16_t)a[a_offset + 11*i+ 5] & 0x0f) << 7); 217 | break; 218 | case 2: 219 | r[b_offset + 8*i+0] = (a[a_offset + 11*i+ 0] >> 0) | (((uint16_t)a[a_offset + 11*i+ 1] & 0x07) << 8); 220 | r[b_offset + 8*i+1] = (a[a_offset + 11*i+ 1] >> 3) | (((uint16_t)a[a_offset + 11*i+ 2] & 0x3f) << 5); 221 | break; 222 | } 223 | r[NTRU_N-1] = 0; 224 | } 225 | } -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/src/packq.cu: -------------------------------------------------------------------------------- 1 | #include "../include/params.h" 2 | #include "../include/packq.cuh" 3 | #include 4 | 5 | __device__ void poly_Sq_frombytes_gpu(uint16_t *r, const unsigned char *a) 6 | { 7 | int i = NTRU_PACK_DEG/8; 8 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 9 | uint32_t b_offset = bid*NTRU_N, a_offset = bid*NTRU_PUBLICKEYBYTES; 10 | 11 | r[b_offset + 8*tid+0] = (a[a_offset + 11*tid+ 0] >> 0) | (((uint16_t)a[a_offset + 11*tid+ 1] & 0x07) << 8); 12 | r[b_offset + 8*tid+1] = (a[a_offset + 11*tid+ 1] >> 3) | (((uint16_t)a[a_offset + 11*tid+ 2] & 0x3f) << 5); 13 | r[b_offset + 8*tid+2] = (a[a_offset + 11*tid+ 2] >> 6) | (((uint16_t)a[a_offset + 11*tid+ 3] & 0xff) << 2) | (((uint16_t)a[a_offset + 11*tid+ 4] & 0x01) << 10); 14 | r[b_offset + 8*tid+3] = (a[a_offset + 11*tid+ 4] >> 1) | (((uint16_t)a[a_offset + 11*tid+ 5] & 0x0f) << 7); 15 | r[b_offset + 8*tid+4] = (a[a_offset + 11*tid+ 5] >> 4) | (((uint16_t)a[a_offset + 11*tid+ 6] & 0x7f) << 4); 16 | r[b_offset + 8*tid+5] = (a[a_offset + 11*tid+ 6] >> 7) | (((uint16_t)a[a_offset + 11*tid+ 7] & 0xff) << 1) | (((uint16_t)a[a_offset + 11*tid+ 8] & 0x03) << 9); 17 | r[b_offset + 8*tid+6] = (a[a_offset + 11*tid+ 8] >> 2) | (((uint16_t)a[a_offset + 11*tid+ 9] & 0x1f) << 6); 18 | r[b_offset + 8*tid+7] = (a[a_offset + 11*tid+ 9] >> 5) | (((uint16_t)a[a_offset + 11*tid+10] & 0xff) << 3); 19 | 20 | if(tid==0) //wklee, can be parallelized later 21 | { 22 | switch(NTRU_PACK_DEG&0x07) 23 | { 24 | // cases 0 and 6 are impossible since 2 generates (Z/n)* and 25 | // p mod 8 in {1, 7} implies that 2 is a quadratic residue. 26 | case 4: 27 | r[b_offset + 8*i+0] = (a[a_offset + 11*i+ 0] >> 0) | (((uint16_t)a[a_offset + 11*i+ 1] & 0x07) << 8); 28 | r[b_offset + 8*i+1] = (a[a_offset + 11*i+ 1] >> 3) | (((uint16_t)a[a_offset + 11*i+ 2] & 0x3f) << 5); 29 | r[b_offset + 8*i+2] = (a[a_offset + 11*i+ 2] >> 6) | (((uint16_t)a[a_offset + 11*i+ 3] & 0xff) << 2) | (((uint16_t)a[a_offset + 11*i+ 4] & 0x01) << 10); 30 | r[b_offset + 8*i+3] = (a[a_offset + 11*i+ 4] >> 1) | (((uint16_t)a[a_offset + 11*i+ 5] & 0x0f) << 7); 31 | break; 32 | case 2: 33 | r[b_offset + 8*i+0] = (a[a_offset + 11*i+ 0] >> 0) | (((uint16_t)a[a_offset + 11*i+ 1] & 0x07) << 8); 34 | r[b_offset + 8*i+1] = (a[a_offset + 11*i+ 1] >> 3) | (((uint16_t)a[a_offset + 11*i+ 2] & 0x3f) << 5); 35 | break; 36 | } 37 | r[NTRU_N-1] = 0; 38 | } 39 | } 40 | 41 | __global__ void poly_Sq_tobytes_gpu(unsigned char *r, const uint16_t *a) 42 | { 43 | int i,j; 44 | uint16_t t[8]; 45 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 46 | uint32_t b_offset = bid*NTRU_CIPHERTEXTBYTES, a_offset = bid*NTRU_N; 47 | 48 | for(j=0;j<8;j++)// wklee, we can remove this, already MOD 49 | t[j] = MODQ(a[a_offset + 8*tid+j]); 50 | 51 | r[b_offset + 11 * tid + 0] = (unsigned char) ( t[0] & 0xff); 52 | r[b_offset + 11 * tid + 1] = (unsigned char) ((t[0] >> 8) | ((t[1] & 0x1f) << 3)); 53 | r[b_offset + 11 * tid + 2] = (unsigned char) ((t[1] >> 5) | ((t[2] & 0x03) << 6)); 54 | r[b_offset + 11 * tid + 3] = (unsigned char) ((t[2] >> 2) & 0xff); 55 | r[b_offset + 11 * tid + 4] = (unsigned char) ((t[2] >> 10) | ((t[3] & 0x7f) << 1)); 56 | r[b_offset + 11 * tid + 5] = (unsigned char) ((t[3] >> 7) | ((t[4] & 0x0f) << 4)); 57 | r[b_offset + 11 * tid + 6] = (unsigned char) ((t[4] >> 4) | ((t[5] & 0x01) << 7)); 58 | r[b_offset + 11 * tid + 7] = (unsigned char) ((t[5] >> 1) & 0xff); 59 | r[b_offset + 11 * tid + 8] = (unsigned char) ((t[5] >> 9) | ((t[6] & 0x3f) << 2)); 60 | r[b_offset + 11 * tid + 9] = (unsigned char) ((t[6] >> 6) | ((t[7] & 0x07) << 5)); 61 | r[b_offset + 11 * tid + 10] = (unsigned char) ((t[7] >> 3)); 62 | __syncthreads(); 63 | if(tid==0)//wklee, can be parallelized later 64 | { 65 | i = 84; 66 | // wklee, we can remove this, already MOD 67 | for(j=0;j> 8) | ((t[1] & 0x1f) << 3); 77 | r[b_offset + 11 * i + 2] = (unsigned char) (t[1] >> 5) | ((t[2] & 0x03) << 6); 78 | r[b_offset + 11 * i + 3] = (unsigned char) (t[2] >> 2) & 0xff; 79 | r[b_offset + 11 * i + 4] = (unsigned char) (t[2] >> 10) | ((t[3] & 0x7f) << 1); 80 | r[b_offset + 11 * i + 5] = (unsigned char) (t[3] >> 7) | ((t[4] & 0x0f) << 4); 81 | break; 82 | case 2: 83 | r[b_offset + 11 * i + 0] = (unsigned char) (t[0] & 0xff); 84 | r[b_offset + 11 * i + 1] = (unsigned char) (t[0] >> 8) | ((t[1] & 0x1f) << 3); 85 | r[b_offset + 11 * i + 2] = (unsigned char) (t[1] >> 5) | ((t[2] & 0x03) << 6); 86 | break; 87 | } 88 | } 89 | } 90 | 91 | 92 | __global__ void poly_Rq_sum_zero_frombytes_gpu(uint16_t *r, uint8_t *a) 93 | { 94 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 95 | uint32_t b_offset = bid*NTRU_N; 96 | int i; 97 | poly_Sq_frombytes_gpu(r,a); 98 | // __syncthreads(); 99 | // /* Set r[n-1] so that the sum of coefficients is zero mod q */ 100 | // if(tid==0) 101 | // { 102 | // // for(i=0;i> 8) + (a & 0xff); // r mod 255 == a mod 255 122 | r = (r >> 4) + (r & 0xf); // r' mod 15 == r mod 15 123 | r = (r >> 2) + (r & 0x3); // r' mod 3 == r mod 3 124 | r = (r >> 2) + (r & 0x3); // r' mod 3 == r mod 3 125 | 126 | t = r - 3; 127 | c = t >> 15; 128 | 129 | return (c&r) ^ (~c&t); 130 | } 131 | 132 | __global__ void poly_S3_frombytes_gpu(uint16_t *r, uint8_t* msg) 133 | { 134 | int i, j; 135 | uint8_t c; 136 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 137 | 138 | if(tid < NTRU_PACK_DEG/5) 139 | { 140 | c = msg[bid*NTRU_SECRETKEYBYTES + tid]; 141 | r[bid*NTRU_N + 5*tid+0] = c; 142 | r[bid*NTRU_N + 5*tid+1] = c * 171 >> 9; // this is division by 3 143 | r[bid*NTRU_N + 5*tid+2] = c * 57 >> 9; // division by 3^2 144 | r[bid*NTRU_N + 5*tid+3] = c * 19 >> 9; // division by 3^3 145 | r[bid*NTRU_N + 5*tid+4] = c * 203 >> 14; // etc. 146 | } 147 | if(tid==0) 148 | { 149 | i = NTRU_PACK_DEG/5; 150 | c = msg[bid*NTRU_SECRETKEYBYTES +i]; 151 | for(j=0; (5*i+j)> 9; 155 | } 156 | r[bid*NTRU_N +NTRU_N-1] = 0; 157 | } 158 | __syncthreads(); 159 | // poly_mod_3_Phi_n(r); 160 | // for(i=0; i (NTRU_PACK_DEG / 5) * 5 // if 5 does not divide NTRU_N-1 177 | 178 | if(tid==0) 179 | { 180 | i = NTRU_PACK_DEG/5; 181 | c = 0; 182 | for(j = NTRU_PACK_DEG - (5*i) - 1; j>=0; j--) 183 | c = (3*c + a[bid*NTRU_N + 5*i+j]) & 255; 184 | msg[bid*NTRU_OWCPA_MSGBYTES + i] = c; 185 | } 186 | #endif 187 | } 188 | 189 | 190 | __global__ void poly_Sq_frombytes_gpu_global(uint16_t *r, const unsigned char *a) 191 | { 192 | int i = NTRU_PACK_DEG/8; 193 | uint32_t tid = threadIdx.x, bid = blockIdx.x; 194 | uint32_t b_offset = bid*NTRU_N, a_offset = bid*NTRU_SECRETKEYBYTES; 195 | 196 | r[b_offset + 8*tid+0] = (a[a_offset + 11*tid+ 0] >> 0) | (((uint16_t)a[a_offset + 11*tid+ 1] & 0x07) << 8); 197 | r[b_offset + 8*tid+1] = (a[a_offset + 11*tid+ 1] >> 3) | (((uint16_t)a[a_offset + 11*tid+ 2] & 0x3f) << 5); 198 | r[b_offset + 8*tid+2] = (a[a_offset + 11*tid+ 2] >> 6) | (((uint16_t)a[a_offset + 11*tid+ 3] & 0xff) << 2) | (((uint16_t)a[a_offset + 11*tid+ 4] & 0x01) << 10); 199 | r[b_offset + 8*tid+3] = (a[a_offset + 11*tid+ 4] >> 1) | (((uint16_t)a[a_offset + 11*tid+ 5] & 0x0f) << 7); 200 | r[b_offset + 8*tid+4] = (a[a_offset + 11*tid+ 5] >> 4) | (((uint16_t)a[a_offset + 11*tid+ 6] & 0x7f) << 4); 201 | r[b_offset + 8*tid+5] = (a[a_offset + 11*tid+ 6] >> 7) | (((uint16_t)a[a_offset + 11*tid+ 7] & 0xff) << 1) | (((uint16_t)a[a_offset + 11*tid+ 8] & 0x03) << 9); 202 | r[b_offset + 8*tid+6] = (a[a_offset + 11*tid+ 8] >> 2) | (((uint16_t)a[a_offset + 11*tid+ 9] & 0x1f) << 6); 203 | r[b_offset + 8*tid+7] = (a[a_offset + 11*tid+ 9] >> 5) | (((uint16_t)a[a_offset + 11*tid+10] & 0xff) << 3); 204 | 205 | if(tid==0) //wklee, can be parallelized later 206 | { 207 | switch(NTRU_PACK_DEG&0x07) 208 | { 209 | // cases 0 and 6 are impossible since 2 generates (Z/n)* and 210 | // p mod 8 in {1, 7} implies that 2 is a quadratic residue. 211 | case 4: 212 | r[b_offset + 8*i+0] = (a[a_offset + 11*i+ 0] >> 0) | (((uint16_t)a[a_offset + 11*i+ 1] & 0x07) << 8); 213 | r[b_offset + 8*i+1] = (a[a_offset + 11*i+ 1] >> 3) | (((uint16_t)a[a_offset + 11*i+ 2] & 0x3f) << 5); 214 | r[b_offset + 8*i+2] = (a[a_offset + 11*i+ 2] >> 6) | (((uint16_t)a[a_offset + 11*i+ 3] & 0xff) << 2) | (((uint16_t)a[a_offset + 11*i+ 4] & 0x01) << 10); 215 | r[b_offset + 8*i+3] = (a[a_offset + 11*i+ 4] >> 1) | (((uint16_t)a[a_offset + 11*i+ 5] & 0x0f) << 7); 216 | break; 217 | case 2: 218 | r[b_offset + 8*i+0] = (a[a_offset + 11*i+ 0] >> 0) | (((uint16_t)a[a_offset + 11*i+ 1] & 0x07) << 8); 219 | r[b_offset + 8*i+1] = (a[a_offset + 11*i+ 1] >> 3) | (((uint16_t)a[a_offset + 11*i+ 2] & 0x3f) << 5); 220 | break; 221 | } 222 | r[NTRU_N-1] = 0; 223 | } 224 | } -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-509/src/cuda_kernel.cu: -------------------------------------------------------------------------------- 1 | // CUDA libraries. 2 | #include 3 | #include 4 | #include 5 | 6 | // Include associated header file. 7 | #include "../include/cuda_kernel.cuh" 8 | #include "../include/tv.h" 9 | #include "../include/params.h" 10 | #include "../include/packq.cuh" 11 | #include "../include/poly.cuh" 12 | #include "../include/check.cuh" 13 | 14 | #include 15 | #include 16 | 17 | 18 | void ntru_enc(uint8_t mode, uint16_t *h_m, uint16_t *h_r, uint8_t *h_pk, uint8_t *h_c) { 19 | half *host_fp16, *h_fp16, *r_fp16; 20 | uint8_t *d_pk, *d_c; 21 | int i, j; 22 | uint16_t *h_h; 23 | uint16_t *d_m, *d_liftm, *d_r, *d_h, *d_ct; 24 | float *c_wmma; 25 | cudaEvent_t start, stop; 26 | float elapsed; 27 | 28 | /* initialize random seed: */ 29 | srand (time(NULL)); // comment out this to yield a static m elements. 30 | cudaEventCreate(&start); cudaEventCreate(&stop); 31 | cudaMallocHost((void**) &h_h, BATCH*NTRU_N* sizeof(uint16_t)); 32 | cudaMallocHost((void**)&host_fp16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(half)); 33 | 34 | cudaMalloc((void**) &d_c, BATCH*NTRU_CIPHERTEXTBYTES * sizeof(uint8_t)); 35 | cudaMalloc((void**) &d_ct, BATCH*NTRU_N_PWR2 * sizeof(uint16_t)); 36 | cudaMalloc((void**) &d_r, BATCH*NTRU_N * sizeof(uint16_t)); 37 | cudaMalloc((void**) &d_m, BATCH*NTRU_N* sizeof(uint16_t)); 38 | cudaMalloc((void**) &d_liftm, BATCH*NTRU_N* sizeof(uint16_t)); 39 | cudaMalloc((void**) &d_h, BATCH*NTRU_N* sizeof(uint16_t)); 40 | cudaMalloc((void**) &d_pk, BATCH*NTRU_PUBLICKEYBYTES* sizeof(uint8_t)); 41 | cudaMalloc((void**)&c_wmma, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(float)); 42 | cudaMalloc((void**)&h_fp16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(half)); 43 | cudaMalloc((void**)&r_fp16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(half)); ; 44 | 45 | // Using the same public-private key pair 46 | for(j=0; jWMMA_THREAD) 58 | { 59 | blocks = threads / WMMA_THREAD; 60 | threads = WMMA_THREAD; 61 | } 62 | 63 | if(mode==0) printf("\n u16 mode N = %d, blocks: %u threads: %u \n\n", NTRU_N, blocks, threads); 64 | else if(mode==1) printf("\n tensor core mode N = %d, blocks: %u threads: %u \n\n", NTRU_N, blocks, threads); 65 | 66 | cudaEventRecord(start); 67 | cudaMemcpy(d_pk, h_pk, BATCH*NTRU_PUBLICKEYBYTES * sizeof(uint8_t), cudaMemcpyHostToDevice); 68 | cudaMemcpy(d_r, h_r, BATCH*NTRU_N*sizeof(uint16_t), cudaMemcpyHostToDevice); 69 | cudaMemcpy(d_m, h_m, BATCH*NTRU_N*sizeof(uint16_t), cudaMemcpyHostToDevice); 70 | 71 | // owcpa_enc 72 | poly_Rq_sum_zero_frombytes_gpu<<>>(d_h, d_pk); 73 | poly_Rq_sum_zero_frombytes_sum_gpu<<>>(d_h); 74 | poly_lift<<>>(d_liftm, d_m); 75 | 76 | if(mode==0) 77 | poly_Rq_mul_gpu_shared<<>>(d_ct, d_r, d_h); 78 | else if(mode==1) 79 | { 80 | convertU16ToFp16Negate<<< K, NTRU_N>>>(r_fp16, d_r); 81 | convertU16ToFp16cyclic<<< NTRU_N, NTRU_N>>>(h_fp16, d_h); 82 | wmma_ker_padding<<< blocks, threads >>> (h_fp16, r_fp16, c_wmma); 83 | convertFp32ToU16mod2048<<>>(d_ct, c_wmma); 84 | } 85 | poly_add<<>>(d_ct, d_liftm); 86 | poly_Sq_tobytes_gpu<<>>(d_c, d_ct); 87 | 88 | // cudaMemcpy(h_h, d_ct, BATCH*NTRU_N * sizeof(uint16_t), cudaMemcpyDeviceToHost); 89 | cudaMemcpy(h_c, d_c, BATCH*NTRU_CIPHERTEXTBYTES * sizeof(uint8_t), cudaMemcpyDeviceToHost); 90 | cudaEventRecord(stop); 91 | cudaEventSynchronize(stop); 92 | cudaEventElapsedTime(&elapsed, start, stop); 93 | if(mode==0) printf("encrypt: gpu u16 mode took %fms average %f us\n", elapsed, elapsed*1000/NTRU_N); 94 | else if(mode==1) printf("encrypt: gpu tensor core mode took %fms average %f us\n", elapsed, elapsed*1000/NTRU_N);; 95 | 96 | // printf("\n h:\n"); for(j=0; j<2; j++) {printf("\nbatch: %u\n", j); for(i=0; iWMMA_THREAD) 142 | { 143 | blocks = threads / WMMA_THREAD; 144 | threads = WMMA_THREAD; 145 | } 146 | 147 | // Using the same public-private key pair 148 | for(j=0; j>>(d_ct, d_c); 154 | poly_Rq_sum_zero_frombytes_sum_gpu<<>>(d_ct); 155 | poly_S3_frombytes_gpu<<>>(d_f, d_sk); 156 | poly_Z3_to_Zq_gpu<<>>(d_f); 157 | if(mode==0) 158 | { 159 | poly_Rq_mul_gpu_shared<<>>(d_cf, d_ct, d_f); 160 | } 161 | else if(mode==1) 162 | { 163 | convertU16ToFp16<<< K, NTRU_N>>>(ct_fp16, d_ct); 164 | convertU16ToFp16Negatecyclic<<< NTRU_N, NTRU_N>>>(f_fp16, d_f); 165 | wmma_ker_padding<<< blocks, threads >>> (f_fp16, ct_fp16, c_wmma); 166 | convertFp32ToU16mod2048<<>>(d_cf, c_wmma); 167 | } 168 | poly_Rq_to_S3_gpu<<>>(d_mf, d_cf); 169 | poly_S3_frombytes_gpu<<>>(d_finv3, d_sk+NTRU_PACK_TRINARY_BYTES); 170 | 171 | // //poly_S3_mul 172 | if(mode==0) 173 | poly_Rq_mul_gpu_shared<<>>(d_m, d_finv3, d_mf); 174 | else if(mode==1) 175 | { 176 | convertU16ToFp16<<< K, NTRU_N>>>(f_fp16, d_mf); 177 | convertU16ToFp16cyclic<<< NTRU_N, NTRU_N>>>(ct_fp16, d_finv3); 178 | wmma_ker_padding<<< blocks, threads >>> (ct_fp16, f_fp16, c_wmma); 179 | convertFp32ToU16mod2048<<>>(d_m, c_wmma); 180 | } 181 | poly_mod_3_Phi_n_gpu<<>>(d_m); 182 | poly_S3_tobytes_gpu<<>>(d_rm+NTRU_PACK_TRINARY_BYTES, d_m); 183 | owcpa_check_ciphertext_gpu<<>>(d_fail, d_c); 184 | owcpa_check_m_gpu<<>>(d_fail, d_m); 185 | // /* b = c - Lift(m) mod (q, x^n - 1) */ 186 | poly_lift<<>>(d_liftm, d_m); 187 | poly_sub<<>>(d_ct, d_liftm); 188 | poly_Sq_frombytes_gpu_global<<>>(d_invh, d_sk+2*NTRU_PACK_TRINARY_BYTES); 189 | 190 | // --> this part cannot use tensor core because both poly are dense, it can overflow the FP32 accumulator in tensor core 191 | // //poly_Sq_mul(r, b, invh); 192 | poly_Rq_mul_gpu_shared<<>>(d_r, d_ct, d_invh); 193 | poly_mod_q_Phi_n_gpu<<>>(d_r); 194 | owcpa_check_r_gpu<<>>(d_fail, d_r); 195 | poly_trinary_Zq_to_Z3_gpu<<>>(d_r); 196 | poly_S3_tobytes_gpu<<>>(d_rm, d_r); 197 | #ifdef DEBUG 198 | cudaMemcpy(h_h, d_m, BATCH*NTRU_N * sizeof(uint16_t), cudaMemcpyDeviceToHost); 199 | #endif 200 | cudaMemcpy(h_rm, d_rm, BATCH*NTRU_OWCPA_MSGBYTES * sizeof(uint8_t), cudaMemcpyDeviceToHost); 201 | // cudaMemcpy(host_fp16, f_fp16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(half), cudaMemcpyDeviceToHost); 202 | cudaEventRecord(stop); 203 | cudaEventSynchronize(stop); 204 | cudaEventElapsedTime(&elapsed, start, stop); 205 | if(mode==0) printf("\ndecrypt: gpu u16 mode took %fms average %f us\n", elapsed, elapsed*1000/NTRU_N); 206 | else if(mode==1) printf("\ndecrypt: gpu tensor core mode took %fms average %f us\n", elapsed, elapsed*1000/NTRU_N);; 207 | 208 | #ifdef DEBUG 209 | // Compare with the plaintext h_m 210 | for(j=0; j 3 | #include 4 | #include 5 | 6 | // Include associated header file. 7 | #include "../include/cuda_kernel.cuh" 8 | #include "../include/tv.h" 9 | #include "../include/params.h" 10 | #include "../include/packq.cuh" 11 | #include "../include/poly.cuh" 12 | #include "../include/check.cuh" 13 | 14 | #include 15 | #include 16 | 17 | 18 | void ntru_enc(uint8_t mode, uint16_t *h_m, uint16_t *h_r, uint8_t *h_pk, uint8_t *h_c) { 19 | half *host_fp16, *h_fp16, *r_fp16; 20 | uint8_t *d_pk, *d_c; 21 | int i, j; 22 | uint16_t *h_h; 23 | uint16_t *d_m, *d_liftm, *d_r, *d_h, *d_ct; 24 | float *c_wmma; 25 | cudaEvent_t start, stop; 26 | float elapsed; 27 | 28 | /* initialize random seed: */ 29 | srand (time(NULL)); // comment out this to yield a static m elements. 30 | cudaEventCreate(&start); cudaEventCreate(&stop); 31 | cudaMallocHost((void**) &h_h, BATCH*NTRU_N* sizeof(uint16_t)); 32 | cudaMallocHost((void**)&host_fp16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(half)); 33 | 34 | cudaMalloc((void**) &d_c, BATCH*NTRU_CIPHERTEXTBYTES * sizeof(uint8_t)); 35 | cudaMalloc((void**) &d_ct, BATCH*NTRU_N_PWR2 * sizeof(uint16_t)); 36 | cudaMalloc((void**) &d_r, BATCH*NTRU_N * sizeof(uint16_t)); 37 | cudaMalloc((void**) &d_m, BATCH*NTRU_N* sizeof(uint16_t)); 38 | cudaMalloc((void**) &d_liftm, BATCH*NTRU_N* sizeof(uint16_t)); 39 | cudaMalloc((void**) &d_h, BATCH*NTRU_N* sizeof(uint16_t)); 40 | cudaMalloc((void**) &d_pk, BATCH*NTRU_PUBLICKEYBYTES* sizeof(uint8_t)); 41 | cudaMalloc((void**)&c_wmma, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(float)); 42 | cudaMalloc((void**)&h_fp16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(half)); 43 | cudaMalloc((void**)&r_fp16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(half)); ; 44 | 45 | // Using the same public-private key pair 46 | for(j=0; jWMMA_THREAD) 58 | { 59 | blocks = threads / WMMA_THREAD; 60 | threads = WMMA_THREAD; 61 | } 62 | 63 | if(mode==0) printf("\n u16 mode N = %d, blocks: %u threads: %u \n\n", NTRU_N, blocks, threads); 64 | else if(mode==1) printf("\n tensor core mode N = %d, blocks: %u threads: %u \n\n", NTRU_N, blocks, threads); 65 | 66 | cudaEventRecord(start); 67 | cudaMemcpy(d_pk, h_pk, BATCH*NTRU_PUBLICKEYBYTES * sizeof(uint8_t), cudaMemcpyHostToDevice); 68 | cudaMemcpy(d_r, h_r, BATCH*NTRU_N*sizeof(uint16_t), cudaMemcpyHostToDevice); 69 | cudaMemcpy(d_m, h_m, BATCH*NTRU_N*sizeof(uint16_t), cudaMemcpyHostToDevice); 70 | 71 | // owcpa_enc 72 | poly_Rq_sum_zero_frombytes_gpu<<>>(d_h, d_pk); 73 | poly_Rq_sum_zero_frombytes_sum_gpu<<>>(d_h); 74 | poly_lift<<>>(d_liftm, d_m); 75 | 76 | if(mode==0) 77 | poly_Rq_mul_gpu_shared<<>>(d_ct, d_r, d_h); 78 | else if(mode==1) 79 | { 80 | convertU16ToFp16Negate<<< K, NTRU_N>>>(r_fp16, d_r); 81 | convertU16ToFp16cyclic<<< NTRU_N, NTRU_N>>>(h_fp16, d_h); 82 | wmma_ker_padding<<< blocks, threads >>> (h_fp16, r_fp16, c_wmma); 83 | convertFp32ToU16mod2048<<>>(d_ct, c_wmma); 84 | } 85 | poly_add<<>>(d_ct, d_liftm); 86 | poly_Sq_tobytes_gpu<<>>(d_c, d_ct); 87 | 88 | // cudaMemcpy(h_h, d_ct, BATCH*NTRU_N * sizeof(uint16_t), cudaMemcpyDeviceToHost); 89 | cudaMemcpy(h_c, d_c, BATCH*NTRU_CIPHERTEXTBYTES * sizeof(uint8_t), cudaMemcpyDeviceToHost); 90 | cudaEventRecord(stop); 91 | cudaEventSynchronize(stop); 92 | cudaEventElapsedTime(&elapsed, start, stop); 93 | if(mode==0) printf("encrypt: gpu u16 mode took %fms average %f us\n", elapsed, elapsed*1000/NTRU_N); 94 | else if(mode==1) printf("encrypt: gpu tensor core mode took %fms average %f us\n", elapsed, elapsed*1000/NTRU_N);; 95 | 96 | // printf("\n h:\n"); for(j=0; j<2; j++) {printf("\nbatch: %u\n", j); for(i=0; iWMMA_THREAD) 142 | { 143 | blocks = threads / WMMA_THREAD; 144 | threads = WMMA_THREAD; 145 | } 146 | 147 | // Using the same public-private key pair 148 | for(j=0; j>>(d_ct, d_c); 154 | poly_Rq_sum_zero_frombytes_sum_gpu<<>>(d_ct); 155 | poly_S3_frombytes_gpu<<>>(d_f, d_sk); 156 | poly_Z3_to_Zq_gpu<<>>(d_f); 157 | if(mode==0) 158 | { 159 | poly_Rq_mul_gpu_shared<<>>(d_cf, d_ct, d_f); 160 | } 161 | else if(mode==1) 162 | { 163 | convertU16ToFp16<<< K, NTRU_N>>>(ct_fp16, d_ct); 164 | convertU16ToFp16Negatecyclic<<< NTRU_N, NTRU_N>>>(f_fp16, d_f); 165 | wmma_ker_padding<<< blocks, threads >>> (f_fp16, ct_fp16, c_wmma); 166 | convertFp32ToU16mod2048<<>>(d_cf, c_wmma); 167 | } 168 | poly_Rq_to_S3_gpu<<>>(d_mf, d_cf); 169 | poly_S3_frombytes_gpu<<>>(d_finv3, d_sk+NTRU_PACK_TRINARY_BYTES); 170 | 171 | // //poly_S3_mul 172 | if(mode==0) 173 | poly_Rq_mul_gpu_shared<<>>(d_m, d_finv3, d_mf); 174 | else if(mode==1) 175 | { 176 | convertU16ToFp16<<< K, NTRU_N>>>(f_fp16, d_mf); 177 | convertU16ToFp16cyclic<<< NTRU_N, NTRU_N>>>(ct_fp16, d_finv3); 178 | wmma_ker_padding<<< blocks, threads >>> (ct_fp16, f_fp16, c_wmma); 179 | convertFp32ToU16mod2048<<>>(d_m, c_wmma); 180 | } 181 | poly_mod_3_Phi_n_gpu<<>>(d_m); 182 | poly_S3_tobytes_gpu<<>>(d_rm+NTRU_PACK_TRINARY_BYTES, d_m); 183 | owcpa_check_ciphertext_gpu<<>>(d_fail, d_c); 184 | owcpa_check_m_gpu<<>>(d_fail, d_m); 185 | // /* b = c - Lift(m) mod (q, x^n - 1) */ 186 | poly_lift<<>>(d_liftm, d_m); 187 | poly_sub<<>>(d_ct, d_liftm); 188 | poly_Sq_frombytes_gpu_global<<>>(d_invh, d_sk+2*NTRU_PACK_TRINARY_BYTES); 189 | 190 | // --> this part cannot use tensor core because both poly are dense, it can overflow the FP32 accumulator in tensor core 191 | // //poly_Sq_mul(r, b, invh); 192 | poly_Rq_mul_gpu_shared<<>>(d_r, d_ct, d_invh); 193 | poly_mod_q_Phi_n_gpu<<>>(d_r); 194 | owcpa_check_r_gpu<<>>(d_fail, d_r); 195 | poly_trinary_Zq_to_Z3_gpu<<>>(d_r); 196 | poly_S3_tobytes_gpu<<>>(d_rm, d_r); 197 | #ifdef DEBUG 198 | cudaMemcpy(h_h, d_m, BATCH*NTRU_N * sizeof(uint16_t), cudaMemcpyDeviceToHost); 199 | #endif 200 | cudaMemcpy(h_rm, d_rm, BATCH*NTRU_OWCPA_MSGBYTES * sizeof(uint8_t), cudaMemcpyDeviceToHost); 201 | // cudaMemcpy(host_fp16, f_fp16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(half), cudaMemcpyDeviceToHost); 202 | cudaEventRecord(stop); 203 | cudaEventSynchronize(stop); 204 | cudaEventElapsedTime(&elapsed, start, stop); 205 | if(mode==0) printf("\ndecrypt: gpu u16 mode took %fms average %f us\n", elapsed, elapsed*1000/NTRU_N); 206 | else if(mode==1) printf("\ndecrypt: gpu tensor core mode took %fms average %f us\n", elapsed, elapsed*1000/NTRU_N);; 207 | 208 | #ifdef DEBUG 209 | // Compare with the plaintext h_m 210 | for(j=0; j 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "params.h" 7 | using namespace nvcuda; 8 | 9 | #define MODQ(X) ((X) & (FRO_Q-1)) 10 | #define MODN(X) ((X) & (FRO_N_PWR2-1)) 11 | // The only dimensions currently supported by WMMA (16x16) 12 | const int WMMA_M = 16; 13 | 14 | __global__ void poly_Rq_mul_gpu_shared(uint16_t *r, uint16_t *g_a, uint16_t *g_b) 15 | { 16 | uint16_t i, sum; 17 | uint32_t tidx = threadIdx.x, bidx = blockIdx.x; 18 | __shared__ uint16_t a[FRO_N], b[FRO_N]; 19 | b[tidx] = g_b[bidx*(FRO_N_PWR2) + tidx]; 20 | a[tidx] = g_a[bidx*(FRO_N_PWR2) + tidx]; 21 | __syncthreads(); 22 | 23 | sum = 0;// use register to accumulate 24 | for(i=0; i a_frag; 48 | // wklee, Read a in row major and b in column major 49 | wmma::fragment b_frag; 50 | wmma::fragment c_frag; 51 | 52 | // Each warp compute 16 elements along index i 53 | uint32_t warpID = (blockIdx.x * blockDim.x + threadIdx.x) / 32; 54 | uint32_t ldA_offset, ldB_offset, row_idx, col_idx, st_offset; 55 | row_idx = warpID%((FRO_N_PWR2)/WMMA_M)*WMMA_M; 56 | col_idx = warpID/((FRO_N_PWR2)/WMMA_M)*WMMA_M; 57 | st_offset = row_idx + col_idx * FRO_N_PWR2 ; 58 | // Initialize the output to zero 59 | wmma::fill_fragment(c_frag, 0.0f); 60 | for (int i = 0; i < (FRO_N_PWR2)/WMMA_M; i ++) 61 | { 62 | ldA_offset = row_idx*(FRO_N_PWR2) + i*WMMA_M; 63 | ldB_offset = col_idx*(FRO_N_PWR2) + i*WMMA_M; 64 | 65 | wmma::load_matrix_sync(a_frag, a + ldA_offset , FRO_N_PWR2); 66 | wmma::load_matrix_sync(b_frag, b + ldB_offset , FRO_N_PWR2); 67 | wmma::mma_sync(c_frag, a_frag, b_frag, c_frag); 68 | } 69 | 70 | wmma::store_matrix_sync(c + st_offset, c_frag, FRO_N_PWR2, wmma::mem_col_major); 71 | } 72 | 73 | __device__ int mod(int a, int b) 74 | { 75 | int r = a % b; 76 | return r < 0 ? r + b : r; 77 | } 78 | 79 | // Cyclic copy 80 | __global__ void convertU16ToFp16cyclic(half *out, uint16_t *in) { 81 | int tidx = threadIdx.x; 82 | int bidx = blockIdx.x; 83 | 84 | out[bidx + tidx * (FRO_N_PWR2)] = in[mod(tidx - bidx, FRO_N)]; 85 | } 86 | 87 | // Cyclic copy with negation 88 | __global__ void convertU16ToFp16Negatecyclic(half *out, uint16_t *in) { 89 | int tidx = threadIdx.x; 90 | int bidx = blockIdx.x; 91 | 92 | uint16_t temp = in[mod(tidx - bidx, FRO_N)]; 93 | if(temp==2047) out[bidx + tidx * (FRO_N_PWR2)] = -1; 94 | else if(temp==2046) out[bidx + tidx * (FRO_N_PWR2)] = -2; 95 | else if(temp==2045) out[bidx + tidx * (FRO_N_PWR2)] = -3; 96 | else if(temp==2044) out[bidx + tidx * (FRO_N_PWR2)] = -4; 97 | else out[bidx + tidx * (FRO_N_PWR2)] = temp; 98 | 99 | } 100 | 101 | // Negate and copy 102 | __global__ void convertU16ToFp16Negate(half *out, uint16_t *in) { 103 | int tidx = threadIdx.x; 104 | int bidx = blockIdx.x; 105 | uint32_t temp = in[bidx * FRO_N_PWR2 + tidx ]; 106 | if(temp == 2047) out[bidx * (FRO_N_PWR2) + tidx] = -1; 107 | else if(temp == 2046) out[bidx * (FRO_N_PWR2) + tidx] = -2; 108 | else if(temp == 2045) out[bidx * (FRO_N_PWR2) + tidx] = -3; 109 | else if(temp == 2044) out[bidx * (FRO_N_PWR2) + tidx] = -4; 110 | else out[bidx * (FRO_N_PWR2) + tidx] = temp; 111 | } 112 | 113 | // Direct copy 114 | __global__ void convertU16ToFp16(half *out, uint16_t *in) { 115 | int tidx = threadIdx.x; 116 | int bidx = blockIdx.x; 117 | 118 | out[bidx * (FRO_N_PWR2) + tidx] = in[bidx * FRO_N_PWR2 + tidx]; 119 | } 120 | 121 | // Straightforward copy 122 | __global__ void convertFp16ToU16 (uint16_t *out, half *in) { 123 | int tidx = threadIdx.x; 124 | int bidx = blockIdx.x; 125 | 126 | out[bidx * FRO_N_PWR2 + tidx] = in[bidx * FRO_N_PWR2 + tidx]; 127 | } 128 | 129 | // Convert and mod 130 | __global__ void convertFp32ToU16mod2048 (uint16_t *out, float *in) { 131 | int tidx = threadIdx.x; 132 | int bidx = blockIdx.x; 133 | int32_t tmp = (int32_t) in[bidx * (FRO_N_PWR2) + tidx]; 134 | 135 | out[bidx * FRO_N_PWR2 + tidx] = MODQ(tmp); 136 | } 137 | 138 | int main(int argc, char* argv[]) { 139 | half *a_fp16, *b_fp16, *h_a_fp16, *h_b_fp16; 140 | float *d_a, *d_b, *d_a_fp32, *d_b_fp32, *d_c_fp32; 141 | float *h_c_wmma, *c_wmma ; 142 | uint32_t i, j, *h_c_mm_u16, *h_a_u32, *h_b_u32, *d_a_u32, *d_b_u32, *h_c_u32, *d_c_u32; 143 | uint16_t *h_c_u16, *h_a_u16, *h_b_u16, *d_a_u16, *d_b_u16, *d_c_u16, *u16_c_wmma, *u16h_c_wmma, *testc; 144 | 145 | cudaEvent_t start, stop; 146 | float elapsed; 147 | 148 | cudaEventCreate(&start); 149 | cudaEventCreate(&stop); 150 | 151 | cudaMalloc((void**)&a_fp16, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(half)); 152 | cudaMalloc((void**)&b_fp16, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(half)); 153 | cudaMalloc((void**)&d_a_u32, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint32_t)); 154 | cudaMalloc((void**)&d_b_u32, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint32_t)); 155 | cudaMalloc((void**)&d_c_u32, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint32_t)); 156 | cudaMalloc((void**)&c_wmma, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(float)); 157 | cudaMalloc((void**)&u16_c_wmma, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint16_t)); 158 | cudaMalloc((void**)&d_a, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(float)); 159 | cudaMalloc((void**)&d_b, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(float)); 160 | cudaMalloc((void**)&d_a_u16, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint16_t)); 161 | cudaMalloc((void**)&d_b_u16, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint16_t)); 162 | cudaMalloc((void**)&d_c_u16, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint16_t)); 163 | cudaMalloc((void**)&d_a_fp32, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(float)); 164 | cudaMalloc((void**)&d_b_fp32, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(float)); 165 | cudaMalloc((void**)&d_c_fp32, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(float)); 166 | 167 | cudaMallocHost((void**)&testc, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint16_t)); 168 | cudaMallocHost((void**)&h_c_wmma, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(float)); 169 | cudaMallocHost((void**)&h_a_u32, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint32_t)); 170 | cudaMallocHost((void**)&h_b_u32, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint32_t)); 171 | cudaMallocHost((void**)&h_c_u32, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint32_t)); 172 | cudaMallocHost((void**)&u16h_c_wmma, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint16_t)); 173 | cudaMallocHost((void**)&h_a_u16, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint16_t)); 174 | cudaMallocHost((void**)&h_b_u16, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint16_t)); 175 | cudaMallocHost((void**)&h_c_u16, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint16_t)); 176 | cudaMallocHost((void**)&h_c_mm_u16, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint32_t)); 177 | cudaMallocHost((void**)&h_a_fp16, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(half)); 178 | cudaMallocHost((void**)&h_b_fp16, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(half)); 179 | 180 | uint32_t t1 = FRO_N_PWR2%WMMA_M, t2 = 0; 181 | if(t1!=0) t2=1; 182 | uint32_t threads; 183 | // each warp computes 16x16 matrix 184 | if(K%16==0) threads = 32 * ((FRO_N_PWR2+t2)/WMMA_M) * ((K+t2)/WMMA_M); 185 | else threads = 32 * ((FRO_N_PWR2+t2)/WMMA_M) * ((K+15+t2)/WMMA_M); 186 | 187 | uint32_t blocks = 1; 188 | if(threads>WMMA_THREAD) 189 | { 190 | blocks = threads / WMMA_THREAD; 191 | threads = WMMA_THREAD; 192 | } 193 | 194 | printf("\nM = %d, PADDING = %d, K= %u, blocks: %u threads: %u \n\n", FRO_N_PWR2, PADDING, K, blocks, threads); 195 | 196 | /* initialize random seed: */ 197 | srand (time(NULL)); // comment out this to yield a static poly elements. 198 | for (i = 0; i >>(d_c_u16, d_a_u16, d_b_u16); 217 | poly_Rq_mul_gpu_shared<<>>(d_c_u16, d_a_u16, d_b_u16); 218 | } 219 | cudaEventRecord(stop); 220 | cudaEventSynchronize(stop); 221 | cudaEventElapsedTime(&elapsed, start, stop); 222 | cudaMemcpy(h_c_u16, d_c_u16, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint16_t), cudaMemcpyHostToDevice); 223 | printf("gpu u16 took %f ms average: %.4fus\n", elapsed/REPEAT, elapsed*1000/REPEAT/K); 224 | 225 | #ifdef DEBUG 226 | printf("gpu u16 result\n"); for (i = K-1; i >>(b_fp16, d_b_u16); 237 | convertU16ToFp16cyclic<<< FRO_N, FRO_N>>>(a_fp16, d_a_u16); 238 | wmma_ker_padding<<< blocks, threads >>> (a_fp16, b_fp16, c_wmma); 239 | convertFp32ToU16mod2048<<>>(u16_c_wmma, c_wmma); 240 | } 241 | cudaEventRecord(stop); 242 | cudaEventSynchronize(stop); 243 | cudaMemcpy(u16h_c_wmma, u16_c_wmma, FRO_N_PWR2 * FRO_N_PWR2 * sizeof(uint16_t), cudaMemcpyDeviceToHost); 244 | float wmmaTime; 245 | cudaEventElapsedTime(&wmmaTime, start, stop); 246 | printf("gpu tensor core took %4fms average: %.4fus \n", wmmaTime/REPEAT, wmmaTime*1000/REPEAT/K); 247 | 248 | #ifdef DEBUG 249 | printf("gpu tensor core result\n"); for (int i = K-1; i < K; i++) { 250 | printf("batch: %u\n", i); 251 | for (j = 0; j 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "params.h" 7 | using namespace nvcuda; 8 | 9 | #define MODQ(X) ((X) & (NTRU_Q-1)) 10 | #define MODN(X) ((X) & (NTRU_N_PWR2-1)) 11 | // The only dimensions currently supported by WMMA (16x16) 12 | const int WMMA_M = 16; 13 | 14 | __global__ void poly_Rq_mul_gpu_shared(uint16_t *r, uint16_t *g_a, uint16_t *g_b) 15 | { 16 | uint16_t i, sum; 17 | uint32_t tidx = threadIdx.x, bidx = blockIdx.x; 18 | __shared__ uint16_t a[NTRU_N], b[NTRU_N]; 19 | b[tidx] = g_b[bidx*(NTRU_N_PWR2) + tidx]; 20 | a[tidx] = g_a[bidx*(NTRU_N_PWR2) + tidx]; 21 | __syncthreads(); 22 | 23 | sum = 0;// use register to accumulate 24 | for(i=0; i a_frag; 48 | // wklee, Read a in row major and b in column major 49 | wmma::fragment b_frag; 50 | wmma::fragment c_frag; 51 | 52 | // Each warp compute 16 elements along index i 53 | uint32_t warpID = (blockIdx.x * blockDim.x + threadIdx.x) / 32; 54 | uint32_t ldA_offset, ldB_offset, row_idx, col_idx, st_offset; 55 | row_idx = warpID%((NTRU_N_PWR2)/WMMA_M)*WMMA_M; 56 | col_idx = warpID/((NTRU_N_PWR2)/WMMA_M)*WMMA_M; 57 | st_offset = row_idx + col_idx * NTRU_N_PWR2 ; 58 | // Initialize the output to zero 59 | wmma::fill_fragment(c_frag, 0.0f); 60 | for (int i = 0; i < (NTRU_N_PWR2)/WMMA_M; i ++) 61 | { 62 | ldA_offset = row_idx*(NTRU_N_PWR2) + i*WMMA_M; 63 | ldB_offset = col_idx*(NTRU_N_PWR2) + i*WMMA_M; 64 | 65 | wmma::load_matrix_sync(a_frag, a + ldA_offset , NTRU_N_PWR2); 66 | wmma::load_matrix_sync(b_frag, b + ldB_offset , NTRU_N_PWR2); 67 | wmma::mma_sync(c_frag, a_frag, b_frag, c_frag); 68 | } 69 | 70 | wmma::store_matrix_sync(c + st_offset, c_frag, NTRU_N_PWR2, wmma::mem_col_major); 71 | } 72 | 73 | __device__ int mod(int a, int b) 74 | { 75 | int r = a % b; 76 | return r < 0 ? r + b : r; 77 | } 78 | 79 | // Cyclic copy 80 | __global__ void convertU16ToFp16cyclic(half *out, uint16_t *in) { 81 | int tidx = threadIdx.x; 82 | int bidx = blockIdx.x; 83 | 84 | out[bidx + tidx * (NTRU_N_PWR2)] = in[mod(tidx - bidx, NTRU_N)]; 85 | } 86 | 87 | // Cyclic copy with negation 88 | __global__ void convertU16ToFp16Negatecyclic(half *out, uint16_t *in) { 89 | int tidx = threadIdx.x; 90 | int bidx = blockIdx.x; 91 | 92 | uint16_t temp = in[mod(tidx - bidx, NTRU_N)]; 93 | if(temp==2047) out[bidx + tidx * (NTRU_N_PWR2)] = -1; 94 | else out[bidx + tidx * (NTRU_N_PWR2)] = temp; 95 | 96 | } 97 | 98 | // Negate and copy 99 | __global__ void convertU16ToFp16Negate(half *out, uint16_t *in) { 100 | int tidx = threadIdx.x; 101 | int bidx = blockIdx.x; 102 | uint32_t temp = in[bidx * NTRU_N_PWR2 + tidx ]; 103 | if(temp == 2047) out[bidx * (NTRU_N_PWR2) + tidx] = -1; 104 | else out[bidx * (NTRU_N_PWR2) + tidx] = temp; 105 | } 106 | 107 | // Direct copy 108 | __global__ void convertU16ToFp16(half *out, uint16_t *in) { 109 | int tidx = threadIdx.x; 110 | int bidx = blockIdx.x; 111 | 112 | out[bidx * (NTRU_N_PWR2) + tidx] = in[bidx * NTRU_N_PWR2 + tidx]; 113 | } 114 | 115 | // Straightforward copy 116 | __global__ void convertFp16ToU16 (uint16_t *out, half *in) { 117 | int tidx = threadIdx.x; 118 | int bidx = blockIdx.x; 119 | 120 | out[bidx * NTRU_N_PWR2 + tidx] = in[bidx * NTRU_N_PWR2 + tidx]; 121 | } 122 | 123 | // Convert and mod 124 | __global__ void convertFp32ToU16mod2048 (uint16_t *out, float *in) { 125 | int tidx = threadIdx.x; 126 | int bidx = blockIdx.x; 127 | int32_t tmp = (int32_t) in[bidx * (NTRU_N_PWR2) + tidx]; 128 | 129 | out[bidx * NTRU_N_PWR2 + tidx] = MODQ(tmp); 130 | } 131 | 132 | int main(int argc, char* argv[]) { 133 | half *a_fp16, *b_fp16, *h_a_fp16, *h_b_fp16; 134 | float *d_a, *d_b, *d_a_fp32, *d_b_fp32, *d_c_fp32; 135 | float *h_c_wmma, *c_wmma ; 136 | uint32_t i, j, *h_c_mm_u16, *h_a_u32, *h_b_u32, *d_a_u32, *d_b_u32, *h_c_u32, *d_c_u32; 137 | uint16_t *h_c_u16, *h_a_u16, *h_b_u16, *d_a_u16, *d_b_u16, *d_c_u16, *u16_c_wmma, *u16h_c_wmma, *testc; 138 | 139 | cudaEvent_t start, stop; 140 | float elapsed; 141 | 142 | cudaEventCreate(&start); 143 | cudaEventCreate(&stop); 144 | 145 | cudaMalloc((void**)&a_fp16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(half)); 146 | cudaMalloc((void**)&b_fp16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(half)); 147 | cudaMalloc((void**)&d_a_u32, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint32_t)); 148 | cudaMalloc((void**)&d_b_u32, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint32_t)); 149 | cudaMalloc((void**)&d_c_u32, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint32_t)); 150 | cudaMalloc((void**)&c_wmma, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(float)); 151 | cudaMalloc((void**)&u16_c_wmma, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint16_t)); 152 | cudaMalloc((void**)&d_a, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(float)); 153 | cudaMalloc((void**)&d_b, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(float)); 154 | cudaMalloc((void**)&d_a_u16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint16_t)); 155 | cudaMalloc((void**)&d_b_u16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint16_t)); 156 | cudaMalloc((void**)&d_c_u16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint16_t)); 157 | cudaMalloc((void**)&d_a_fp32, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(float)); 158 | cudaMalloc((void**)&d_b_fp32, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(float)); 159 | cudaMalloc((void**)&d_c_fp32, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(float)); 160 | 161 | cudaMallocHost((void**)&testc, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint16_t)); 162 | cudaMallocHost((void**)&h_c_wmma, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(float)); 163 | cudaMallocHost((void**)&h_a_u32, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint32_t)); 164 | cudaMallocHost((void**)&h_b_u32, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint32_t)); 165 | cudaMallocHost((void**)&h_c_u32, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint32_t)); 166 | cudaMallocHost((void**)&u16h_c_wmma, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint16_t)); 167 | cudaMallocHost((void**)&h_a_u16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint16_t)); 168 | cudaMallocHost((void**)&h_b_u16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint16_t)); 169 | cudaMallocHost((void**)&h_c_u16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint16_t)); 170 | cudaMallocHost((void**)&h_c_mm_u16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint32_t)); 171 | cudaMallocHost((void**)&h_a_fp16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(half)); 172 | cudaMallocHost((void**)&h_b_fp16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(half)); 173 | 174 | uint32_t t1 = NTRU_N_PWR2%WMMA_M, t2 = 0; 175 | if(t1!=0) t2=1; 176 | uint32_t threads; 177 | if(K%16==0) threads = 32 * ((NTRU_N_PWR2+t2)/WMMA_M) * ((K+t2)/WMMA_M); 178 | else threads = 32 * ((NTRU_N_PWR2+t2)/WMMA_M) * ((K+15+t2)/WMMA_M); 179 | 180 | uint32_t blocks = 1; 181 | if(threads>WMMA_THREAD) 182 | { 183 | blocks = threads / WMMA_THREAD; 184 | threads = WMMA_THREAD; 185 | } 186 | 187 | printf("\nM = %d, PADDING = %d, K= %u, blocks: %u threads: %u \n\n", NTRU_N_PWR2, PADDING, K, blocks, threads); 188 | 189 | /* initialize random seed: */ 190 | srand (time(NULL)); // comment out this to yield a static poly elements. 191 | #ifdef ENCRYPT 192 | // This is for encryption 193 | for (i = 0; i >>(d_c_u16, d_a_u16, d_b_u16); 223 | poly_Rq_mul_gpu_shared<<>>(d_c_u16, d_a_u16, d_b_u16); 224 | } 225 | cudaEventRecord(stop); 226 | cudaEventSynchronize(stop); 227 | cudaEventElapsedTime(&elapsed, start, stop); 228 | cudaMemcpy(h_c_u16, d_c_u16, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint16_t), cudaMemcpyHostToDevice); 229 | printf("gpu u16 took %f ms average: %.4fus\n", elapsed/REPEAT, elapsed*1000/REPEAT/K); 230 | 231 | #ifdef DEBUG 232 | printf("gpu u16 result\n"); for (i = 0; i >>(b_fp16, d_b_u16); 244 | convertU16ToFp16cyclic<<< NTRU_N, NTRU_N>>>(a_fp16, d_a_u16); 245 | wmma_ker_padding<<< blocks, threads >>> (a_fp16, b_fp16, c_wmma); 246 | #else 247 | convertU16ToFp16<<< NTRU_N, NTRU_N>>>(b_fp16, d_b_u16); 248 | convertU16ToFp16Negatecyclic<<< NTRU_N, NTRU_N>>>(a_fp16, d_a_u16); 249 | wmma_ker_padding<<< blocks, threads >>> (a_fp16, b_fp16, c_wmma); 250 | #endif 251 | convertFp32ToU16mod2048<<>>(u16_c_wmma, c_wmma); 252 | } 253 | cudaEventRecord(stop); 254 | cudaEventSynchronize(stop); 255 | cudaMemcpy(u16h_c_wmma, u16_c_wmma, NTRU_N_PWR2 * NTRU_N_PWR2 * sizeof(uint16_t), cudaMemcpyDeviceToHost); 256 | float wmmaTime; 257 | cudaEventElapsedTime(&wmmaTime, start, stop); 258 | printf("gpu tensor core took %4fms average: %.4fus \n", wmmaTime/REPEAT, wmmaTime*1000/REPEAT/K); 259 | 260 | #ifdef DEBUG 261 | printf("gpu tensor core result\n"); for (int i = 0; i < NTRU_N_PWR2; i++) { 262 | printf("batch: %u\n", i); 263 | for (j = 0; j 2 | #include "../include/params.h" 3 | 4 | uint8_t pk_tv[NTRU_PUBLICKEYBYTES] = { 5 | 0xea, 0xd4, 0xd1, 0xaf, 0xf7, 0x80, 0xd5, 0xae, 0xaf, 0x59, 0x0d, 0x73, 0xb4, 0x4b, 0x01, 0xc8, 0xe4, 0x5b, 0xc3, 0xb9, 0xee, 0xc0, 0xb9, 0x02, 0x90, 0xc7, 0xbc, 0xee, 0xd3, 0x38, 0x49, 0xf3, 0xfd, 0xd6, 0xba, 0x3d, 0x2c, 0x34, 0xef, 0x56, 0x52, 0xfc, 0xab, 0x9f, 0x76, 0x93, 0x0e, 0xe4, 0x9b, 0x44, 0x8a, 0xc4, 0x94, 0xdf, 0xbc, 0x18, 0x2a, 0x78, 0xf1, 0x0d, 0xd7, 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xbe, 0xa3, 0x33, 0xdd, 0x1f, 0xca, 0x1b, 0x90, 0x67, 0x18, 0x5d, 0xc7, 0x89, 0x00, 0x86, 0x04, 0x14, 0x50, 0x5a, 0x32, 0x43, 0x14, 0x34, 0xe6, 0xf7, 0xcc, 0x86, 0xc0, 0x68, 0xf8, 0x72, 0xde, 0xac, 0xc9, 0xd2, 0x39, 0xdd, 0xc1, 0xc9, 0x86, 0x31, 0x93, 0xc9, 0xa1, 0x3b, 0x91, 0x49, 0x2b, 0xa2, 0x3b, 0x13, 0xe4, 0xc6, 0xd3, 0x3b, 0xba, 0x43, 0xe0, 0x50, 0x91, 0x0a, 0x67, 0x96, 0x10, 0x9b, 0x4d, 0xc4, 0x19, 0x87, 0x28, 0x75, 0x09, 0x43, 0xa5, 0xca, 0x6a, 0x6b, 0x76, 0x13, 0xac, 0x40, 0x0e,}; 6 | 7 | uint16_t r_tv[NTRU_N] = { 8 | 0x0000, 0x0001, 0x07ff, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0000, 0x0000, 0x07ff, 0x0001, 0x0000, 0x0001, 0x07ff, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0001, 0x0000, 0x0000, 0x07ff, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x07ff, 0x0000, 0x0000, 0x07ff, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x0001, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0001, 0x0001, 0x0000, 0x0001, 0x07ff, 0x0001, 0x0001, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x0000, 0x07ff, 0x0001, 0x0001, 0x0001, 0x0000, 0x07ff, 0x0000, 0x07ff, 0x07ff, 0x0001, 0x0001, 0x0001, 0x07ff, 0x0001, 0x0001, 0x0000, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x07ff, 0x0001, 0x0000, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0001, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x0001, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x0000, 0x07ff, 0x0001, 0x0000, 0x07ff, 0x0001, 0x07ff, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x07ff, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x07ff, 0x0001, 0x0001, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x0001, 0x07ff, 0x0000, 0x07ff, 0x0000, 0x0001, 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x07ff, 0x0001, 0x0001, 0x0001, 0x0000, 0x0001, 0x0001, 0x0000, 0x0001, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x0001, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x07ff, 0x0001, 0x0001, 0x0001, 0x0000, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x0000, 0x0000, 0x0000, 0x07ff, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x0001, 0x07ff, 0x0001, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x07ff, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0001, 0x0001, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x0001, 0x07ff, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0000, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x0001, 0x0001, 0x0000, 0x07ff, 0x0000, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x07ff, 0x07ff, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x07ff, 0x0001, 0x07ff, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x07ff, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x0001, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000, 0x0001, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x0001, 0x0001, 0x0000, 0x0000, 0x07ff, 0x0001, 0x0000, 0x0000}; 9 | 10 | uint16_t m_tv[NTRU_N] = {0x0000, 0x0001, 0x0002, 0x0002, 0x0000, 0x0000, 0x0000, 0x0002, 0x0001, 0x0002, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0002, 0x0002, 0x0000, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0002, 0x0000, 0x0002, 0x0001, 0x0002, 0x0001, 0x0002, 0x0000, 0x0000, 0x0002, 0x0000, 0x0001, 0x0002, 0x0000, 0x0000, 0x0000, 0x0002, 0x0001, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0002, 0x0001, 0x0000, 0x0001, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0002, 0x0001, 0x0002, 0x0000, 0x0001, 0x0002, 0x0000, 0x0001, 0x0001, 0x0002, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0002, 0x0001, 0x0000, 0x0000, 0x0002, 0x0000, 0x0001, 0x0001, 0x0002, 0x0002, 0x0000, 0x0001, 0x0002, 0x0000, 0x0002, 0x0000, 0x0000, 0x0002, 0x0000, 0x0001, 0x0002, 0x0000, 0x0002, 0x0002, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0002, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0002, 0x0001, 0x0000, 0x0001, 0x0002, 0x0000, 0x0002, 0x0001, 0x0002, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0001, 0x0002, 0x0002, 0x0001, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0002, 0x0002, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0002, 0x0001, 0x0000, 0x0002, 0x0001, 0x0002, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x0002, 0x0000, 0x0002, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0002, 0x0002, 0x0002, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0002, 0x0001, 0x0000, 0x0000, 0x0000, 0x0002, 0x0002, 0x0001, 0x0000, 0x0001, 0x0000, 0x0000, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0000, 0x0000, 0x0002, 0x0002, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0002, 0x0000, 0x0002, 0x0002, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0002, 0x0000, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0001, 0x0000, 0x0000, 0x0002, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0002, 0x0001, 0x0000, 0x0000, 0x0001, 0x0002, 0x0002, 0x0000, 0x0000, 0x0002, 0x0000, 0x0002, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x0002, 0x0002, 0x0002, 0x0001, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0002, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0002, 0x0001, 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x0002, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0002, 0x0000, 0x0001, 0x0002, 0x0001, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x0002, 0x0000, 0x0001, 0x0001, 0x0002, 0x0002, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0000, 0x0002, 0x0001, 0x0000, 0x0002, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x0001, 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0002, 0x0000, 0x0001, 0x0002, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0002, 0x0000, 0x0001, 0x0002, 0x0000, 0x0000, 0x0001, 0x0002, 0x0000, 0x0000, 0x0002, 0x0002, 0x0002, 0x0000, 0x0002, 0x0000, 0x0002, 0x0001, 0x0000, 0x0002, 0x0001, 0x0002, 0x0002, 0x0002, 0x0001, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0001, 0x0000, 0x0002, 0x0002, 0x0000, 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x0001, 0x0000, 0x0002, 0x0000, 0x0002, 0x0001, 0x0001, 0x0001, 0x0000, 0x0002, 0x0000}; 11 | 12 | uint8_t sk_tv[NTRU_SECRETKEYBYTES] = { 13 | 0xd0, 0x67, 0xd9, 0x8f, 0x00, 0x55, 0xe2, 0xc3, 0xde, 0xef, 0x10, 0x76, 0xbb, 0xb7, 0x55, 0xaf, 0xd0, 0x65, 0x11, 0x2c, 0x85, 0xc4, 0x6e, 0x6c, 0x35, 0x06, 0x55, 0xd9, 0x62, 0x50, 0x73, 0xe9, 0x4e, 0x45, 0x28, 0xc0, 0x53, 0xe7, 0x20, 0x20, 0x6c, 0xdb, 0x78, 0x0a, 0x61, 0xad, 0x51, 0x20, 0xc4, 0x98, 0xa4, 0xcd, 0x3e, 0x60, 0xc3, 0x34, 0xd8, 0x70, 0x2f, 0x0f, 0x79, 0xd8, 0x14, 0x18, 0xaf, 0x95,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d, 0x3d, 0x97, 0x65, 0x96, 0x0b, 0xda, 0x0d, 0x3a, 0x5b, 0x1a, 0x05, 0x38, 0x26, 0x70, 0xd9, 0x01, 0xb5, 0x3b, 0x6f, 0x44, 0xab, 0x92, 0x40, 0xda, 0x7f, 0x1b, 0xea, 0xe8, 0x1c, 0xa8, 0xc2, 0x79, 0x0d, 0x1d, 0xf2, 0xa8, 0xb1, 0x88, 0x12, 0xf1, 0xb2, 0xf7, 0x7c, 0x83, 0x8e, 0xc1, 0x78, 0x97, 0x58, 0xa5, 0xb6, 0xff, 0x68, 0x16, 0x21, 0xfb, 0x73, 0x58, 0x9a, 0xed, 0xef, 0x43, 0x06, 0x2c, 0x0f, 0x99, 0xc1, 0x5f, 0xb7, 0x79, 0xf6, 0x9e, 0xbc, 0xa3, 0x94, 0x44, 0xeb, 0x97, 0xbc, 0x88, 0x02, 0xf6, 0x26, 0xc8, 0xb1, 0x5d, 0xe6, 0x66, 0xcc, 0xb5, 0xca, 0x52, 0x61, 0x2e, 0xa1, 0xd5, 0x94, 0xe8, 0xae, 0xd6, 0x2c, 0x04, 0x1d, 0xab, 0x03, 0x17, 0xf0, 0xce, 0x5a, 0x41, 0xce, 0x76, 0x72, 0x95, 0x3d, 0x30, 0x1c, 0xff, 0xd7, 0x10, 0xf8, 0x0b, 0xea, 0xc3, 0xf1, 0x9c, 0x0e, 0x96, 0xe6, 0x8c, 0xf8, 0xfd, 0xab, 0x81}; 14 | 15 | // int32_t s_tv[NTRU_N-1]= {134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016}; -------------------------------------------------------------------------------- /NTRU/NTRU-GPU-677/include/tv.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../include/params.h" 3 | 4 | uint8_t pk_tv[NTRU_PUBLICKEYBYTES] = { 5 | 0x57, 0xee, 0xe1, 0x13, 0xd3, 0x50, 0x6f, 0x11, 0x1c, 0xa9, 0xf2, 0x53, 0xd1, 0x03, 0x5c, 0x2a, 0xcc, 0xf6, 0x82, 0x12, 0x48, 0x87, 0x24, 0xfa, 0x9e, 0xb1, 0x44, 0xf5, 0xd3, 0x53, 0x2e, 0x69, 0x14, 0xdf, 0xde, 0x79, 0x86, 0x1d, 0x84, 0x3a, 0x26, 0xf0, 0xa8, 0xd4, 0x33, 0x71, 0xee, 0x27, 0x3d, 0x53, 0xb9, 0x08, 0x79, 0xfd, 0x8c, 0x2f, 0x98, 0x5f, 0x53, 0xc5, 0x9b, 0x33, 0x87, 0x84, 0xb8, 0x80, 0x95, 0x28, 0x4e, 0xb5, 0xa4, 0x9d, 0xc6, 0xb5, 0x01, 0x8c, 0xca, 0x08, 0x06, 0x24, 0x7b, 0xd6, 0x9e, 0xb6, 0x2e, 0x1c, 0x14, 0x31, 0x94, 0x7a, 0x90, 0xed, 0x85, 0x49, 0xf7, 0x91, 0x83, 0xb2, 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a, 0x7b, 0x7b, 0x87, 0x9d, 0xb9, 0xf5, 0xce, 0x81, 0x77, 0x29, 0xe8, 0x24, 0x9d, 0x1a, 0x6b, 0xbe, 0x70, 0x09, 0x2d, 0x98, 0x9e, 0x1a, 0x23, 0xcc, 0xe2, 0xe0, 0x40, 0x19, 0x0b, 0x77, 0x94, 0xe2, 0x79, 0x85, 0x18, 0xd2, 0x9b, 0x75, 0xac, 0x10, 0xcd, 0xc9, 0xfb, 0xe8, 0x97, 0xba, 0x48, 0x92, 0x28, 0x85, 0x3f, 0x7a, 0xfc, 0xec, 0x4a, 0x71, 0xb3, 0x56, 0x33, 0xa9, 0xcf, 0xb5, 0x84, 0x29, 0xa6, 0x2c, 0x9b, 0xec, 0x7d, 0xac, 0xf6, 0x6e, 0x94, 0xef, 0x62, 0x01, 0x0e, 0x98, 0x12, 0x8c, 0x63, 0x61, 0xc5, 0xa8, 0xc5, 0x10, 0x67, 0xe1, 0xff, 0x45, 0xca, 0x02}; 6 | 7 | uint16_t r_tv[NTRU_N] = { 8 | 0x07ff, 0x0001, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x0001, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x0001, 0x07ff, 0x0001, 0x0001, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0001, 0x07ff, 0x0000, 0x07ff, 0x0001, 0x0000, 0x07ff, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x0001, 0x0001, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0000, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x07ff, 0x0001, 0x0001, 0x0000, 0x0000, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x0001, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0000, 0x07ff, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x0001, 0x07ff, 0x0001, 0x0000, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x0000, 0x07ff, 0x0001, 0x07ff, 0x0000, 0x0001, 0x0001, 0x0001, 0x07ff, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x07ff, 0x0001, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x0001, 0x0001, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0001, 0x07ff, 0x0000, 0x07ff, 0x0001, 0x0000, 0x07ff, 0x0000, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x07ff, 0x0001, 0x07ff, 0x0001, 0x0000, 0x07ff, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x0000, 0x07ff, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0001, 0x07ff, 0x0000, 0x07ff, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0001, 0x0001, 0x0000, 0x07ff, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x07ff, 0x0000, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x0000, 0x0000, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x07ff, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x0000, 0x0000, 0x07ff, 0x0001, 0x0000, 0x0000, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0000, 0x0001, 0x07ff, 0x0001, 0x0000, 0x07ff, 0x0001, 0x0001, 0x0000, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x07ff, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0001, 0x0001, 0x0000, 0x0000, 0x07ff, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x0001, 0x0000, 0x0001, 0x07ff, 0x0001, 0x0001, 0x07ff, 0x0001, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x0000, 0x0000, 0x0001, 0x0000, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x07ff, 0x0000, 0x0000, 0x07ff, 0x0001, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x07ff, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x0001, 0x0001, 0x07ff, 0x0000, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0000, 0x07ff, 0x0001, 0x0000, 0x07ff, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x0000, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x0000, 0x0000, 0x07ff, 0x0001, 0x0001, 0x0001, 0x0000, 0x07ff, 0x0001, 0x0001, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0001, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x07ff, 0x0000, 0x0001, 0x0001, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x0001, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x0001, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0001, 0x07ff, 0x0001, 0x0001, 0x0001, 0x07ff, 0x0001, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x07ff, 0x0001, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x07ff, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x07ff, 0x0001, 0x0000, 0x0000, 0x0001, 0x07ff, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x0001, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff, 0x0001, 0x0001, 0x0000, 0x07ff, 0x0001, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x0001, 0x0001, 0x0000, 0x07ff, 0x07ff, 0x0001, 0x0000, 0x07ff, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x07ff, 0x0000, 0x07ff, 0x07ff, 0x0000, 0x0001, 0x07ff, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x07ff, 0x07ff, 0x0000}; 9 | 10 | uint16_t m_tv[NTRU_N] = {0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0002, 0x0002, 0x0000, 0x0001, 0x0001, 0x0000, 0x0001, 0x0000, 0x0000, 0x0002, 0x0002, 0x0001, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0000, 0x0002, 0x0000, 0x0002, 0x0002, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0002, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0001, 0x0002, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0002, 0x0001, 0x0002, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0002, 0x0002, 0x0000, 0x0002, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0002, 0x0000, 0x0001, 0x0002, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0002, 0x0002, 0x0000, 0x0001, 0x0001, 0x0002, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0002, 0x0000, 0x0002, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0000, 0x0000, 0x0001, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0002, 0x0001, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0002, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0001, 0x0001, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0002, 0x0002, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0002, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0002, 0x0002, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0002, 0x0001, 0x0000, 0x0000, 0x0002, 0x0000, 0x0002, 0x0000, 0x0002, 0x0000, 0x0000, 0x0002, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0002, 0x0002, 0x0002, 0x0001, 0x0001, 0x0000, 0x0001, 0x0002, 0x0000, 0x0001, 0x0002, 0x0002, 0x0002, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x0002, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0002, 0x0002, 0x0000, 0x0000, 0x0002, 0x0002, 0x0000, 0x0000, 0x0001, 0x0002, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0002, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0002, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0002, 0x0002, 0x0002, 0x0002, 0x0001, 0x0000, 0x0000, 0x0001, 0x0002, 0x0000, 0x0000, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0002, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0002, 0x0002, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0000, 0x0001, 0x0002, 0x0002, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0002, 0x0002, 0x0000, 0x0000, 0x0001, 0x0000, 0x0001, 0x0001, 0x0000, 0x0001, 0x0002, 0x0000, 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x0002, 0x0002, 0x0002, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000, 0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0001, 0x0000, 0x0000, 0x0002, 0x0001, 0x0002, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0002, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0001, 0x0000, 0x0001, 0x0000, 0x0000, 0x0002, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000}; 11 | 12 | uint8_t sk_tv[NTRU_SECRETKEYBYTES] = { 13 | 0xd0, 0x67, 0xd9, 0x8f, 0x00, 0x55, 0xe2, 0xc3, 0xde, 0xef, 0x10, 0x76, 0xbb, 0xb7, 0x55, 0xaf, 0xd0, 0x65, 0x11, 0x2c, 0x85, 0xc4, 0x6e, 0x6c, 0x35, 0x06, 0x55, 0xd9, 0x62, 0x50, 0x73, 0xe9, 0x4e, 0x45, 0x28, 0xc0, 0x53, 0xe7, 0x20, 0x20, 0x6c, 0xdb, 0x78, 0x0a, 0x61, 0xad, 0x51, 0x20, 0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0x08, 0x5c, 0x07, 0x7e, 0xae, 0x0e, 0xb3, 0xb5, 0xcd, 0x73, 0xda, 0xf3, 0xd1, 0xf0, 0x5c, 0x29, 0x70, 0xf3, 0xe9, 0x62, 0xb6, 0x65, 0xa6, 0x04, 0xdc, 0xb5, 0x88, 0x87, 0xa0, 0x83, 0xcc, 0x5a, 0x91, 0x1f, 0x40, 0xef, 0x6b, 0x78, 0x00, 0x9b, 0x14, 0x31, 0xc1, 0x5c, 0xce, 0x02, 0xb8, 0xc0, 0x84, 0x1d, 0xaf, 0x4d, 0x39, 0x75, 0x0f, 0xd7, 0x3e, 0xb8, 0xa5, 0x00, 0x42, 0xbc, 0xa6, 0x13, 0x9f, 0x76, 0x44, 0x81, 0xfc, 0x96, 0xce, 0xb4, 0x68, 0xcd, 0xac, 0x15, 0x76, 0xae}; 14 | 15 | int32_t s_tv[NTRU_N-1]= {134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686017, 134744073, 538976289, -2139062143, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062142, 33686018, 134744074, 538976290, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016, 134744072, 538976288, -2139062144, 33686016}; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------