/*
 * Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd.
 *
 * Author:     Iceyer <me@iceyer.net>
 *
 * Maintainer: Iceyer <me@iceyer.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _DEEPIN_LICENSE_RSA_CRYPT_H_
#define _DEEPIN_LICENSE_RSA_CRYPT_H_

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <assert.h>

#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/rsa.h>
#include <openssl/sha.h>
#include <openssl/rand.h>
#include <openssl/pem.h>

#ifdef __cplusplus
extern "C" {
#endif

EVP_PKEY *rsa_read_publice_key(const char *keyfile);

int encrypt_init(void);

void encrypt_cleanup(void);

/* Returns 0 for success, non-0 otherwise */
int rsa_sign(const unsigned char *msg, size_t mlen, unsigned char **sig, size_t *slen, EVP_PKEY *pkey);

/* Returns 0 for success, non-0 otherwise */
int rsa_verify(const unsigned char *msg, size_t mlen, const unsigned char *sig, size_t slen, EVP_PKEY *pkey);

#ifdef __cplusplus
}
#endif

typedef unsigned char byte;

#endif //_DEEPIN_LICENSE_RSA_CRYPT_H_
