YARP
Yet Another Robot Platform
AuthHMAC.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2010 Daniel Krieg <krieg@fias.uni-frankfurt.de>
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_OS_IMPL_AUTHHMAC_H
11 #define YARP_OS_IMPL_AUTHHMAC_H
12 
13 #include <yarp/os/InputStream.h>
14 #include <yarp/os/OutputStream.h>
15 
16 #include <hmac_sha2.h>
17 
18 #define DIGEST_SIZE SHA256_DIGEST_SIZE
19 #define HMAC_CONTEXT hmac_sha256_ctx
20 #define HMAC_INIT hmac_sha256_init
21 #define HMAC_REINIT hmac_sha256_reinit
22 #define HMAC_UPDATE hmac_sha256_update
23 #define HMAC_FINAL hmac_sha256_final
24 #define NONCE_LEN 8
25 
26 namespace yarp {
27 namespace os {
28 namespace impl {
29 
34 {
35 public:
39  AuthHMAC();
40 
44  virtual ~AuthHMAC() = default;
45 
46  bool authSource(yarp::os::InputStream* streamIn, yarp::os::OutputStream* streamOut);
47  bool authDest(yarp::os::InputStream* streamIn, yarp::os::OutputStream* streamOut);
48 
49 private:
50  static bool send_hmac(yarp::os::OutputStream* stream, unsigned char* nonce, unsigned char* mac);
51  static bool receive_hmac(yarp::os::InputStream* stream, unsigned char* nonce, unsigned char* mac);
52  static bool check_hmac(unsigned char* mac, unsigned char* mac_check);
53  static void fill_nonce(unsigned char* nonce);
54 
55  bool authentication_enabled;
56  HMAC_CONTEXT context;
57 };
58 
59 } // namespace impl
60 } // namespace os
61 } // namespace yarp
62 
63 #endif // YARP_OS_IMPL_AUTHHMAC_H
yarp::os::impl::AuthHMAC::~AuthHMAC
virtual ~AuthHMAC()=default
Destructor.
yarp::os::OutputStream
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:25
OutputStream.h
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
YARP_os_impl_API
#define YARP_os_impl_API
Definition: api.h:45
InputStream.h
HMAC_CONTEXT
#define HMAC_CONTEXT
Definition: AuthHMAC.h:19
yarp::os::InputStream
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:29
yarp::os::impl::AuthHMAC
3-way authentication via HMAC
Definition: AuthHMAC.h:34