summaryrefslogtreecommitdiff
path: root/util/signer/common/gnubby.h
blob: 88298622683063db84591ec2ae50575ba650cd82 (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
/* Copyright 2015 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#ifndef __EC_UTIL_SIGNER_COMMON_GNUBBY_H
#define __EC_UTIL_SIGNER_COMMON_GNUBBY_H

#include <stddef.h>
#include <inttypes.h>

#include <libusb-1.0/libusb.h>

typedef struct env_md_ctx_st EVP_MD_CTX;
typedef struct evp_pkey_st EVP_PKEY;

class Gnubby {
 public:
  Gnubby();
  ~Gnubby();

  bool ok() const { return handle_ != NULL; }

  int Sign(EVP_MD_CTX* ctx, uint8_t* signature, uint32_t* siglen, EVP_PKEY* key);

 private:
  int send_to_device(uint8_t instruction,
                     const uint8_t* payload,
                     size_t length);

  int receive_from_device(uint8_t* dest, size_t length);

  libusb_context* ctx_;
  libusb_device_handle* handle_;
};

#define MAX_APDU_SIZE 1200
#define LIBUSB_ERR -1

#define VERBOSE

#endif // __EC_UTIL_SIGNER_COMMON_GNUBBY_H