aboutsummaryrefslogtreecommitdiff
path: root/io.h
blob: 430b2f929eeec4f3ef61bf8935c55c58ca4c4097 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
  This file is part of msr.

  msr 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
  (at your option) any later version.
  
  msr 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <string.h>
#include <termios.h>
#include <unistd.h>

#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <time.h>

#include <sodium.h>

#include "utils.h"
#include "base64.h"
#include "crypto.h"

#define DEFAULT_COMMENT_PREFIX  "untrusted comment: "
#define DEFAULT_COMMENT_TEXT "signature generated by msr"

#define DEFAULT_TCOMMENT_PREFIX "trusted comment: "
#define DEFAULT_TCOMMENT_FORMAT "timestamp=%lu, file=%s"

#define DEFAULT_PUBKEY_PREFIX "public key "
#define DEFAULT_SECKEY_PREFIX "encrypted secret key generated by msr"

#define DEFAULT_SIG_DELIM "--- BEGIN SIGNATURE ---"

#define MAX_PASS_LEN 1024
#define MAX_COMMENT_LEN 512
#define MAX_FILENAME_LEN 1024

static char verbose = 1;


Error unlock_seckey(const char * const passwdfn, SecretKey sk);

Error generate_to_file(const char * fn,
                       const char * const passwdfn,
                       const char * const pkcomment,
                       const char * const skcomment);

Error read_pubkey_string(const char * const str, PublicKey *pk);
Error read_seckey_string(const char * const str, SecretKey *sk);

Error read_pubkey_file(const char * const fn,
                       PublicKey *pk);
Error read_seckey_file(const char * const fn,
                       SecretKey *sk);

Error sign_attached(const char * const fn,
                    const char * const passwdfn, SecretKey sk);

Error sign_detached(const char * const fn, const char * const sfn,
                    const char * const comment, const char * const trusted_comment,
                    const char * const passwdfn, SecretKey sk);

Error verify_attached(const char * const fn, PublicKey pk);

Error verify_detached(const char * const fn, const char * const sfn,
                      PublicKey pk);