YARP
Yet Another Robot Platform
AuthHMAC.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2010 Daniel Krieg <krieg@fias.uni-frankfurt.de>
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef YARP_OS_IMPL_AUTHHMAC_H
8 #define YARP_OS_IMPL_AUTHHMAC_H
9 
10 #include <yarp/os/InputStream.h>
11 #include <yarp/os/OutputStream.h>
12 
13 #include <hmac_sha2.h>
14 
15 #define DIGEST_SIZE SHA256_DIGEST_SIZE
16 #define HMAC_CONTEXT hmac_sha256_ctx
17 #define HMAC_INIT hmac_sha256_init
18 #define HMAC_REINIT hmac_sha256_reinit
19 #define HMAC_UPDATE hmac_sha256_update
20 #define HMAC_FINAL hmac_sha256_final
21 #define NONCE_LEN 8
22 
23 namespace yarp {
24 namespace os {
25 namespace impl {
26 
31 {
32 public:
36  AuthHMAC();
37 
41  virtual ~AuthHMAC() = default;
42 
43  bool authSource(yarp::os::InputStream* streamIn, yarp::os::OutputStream* streamOut);
44  bool authDest(yarp::os::InputStream* streamIn, yarp::os::OutputStream* streamOut);
45 
46 private:
47  static bool send_hmac(yarp::os::OutputStream* stream, unsigned char* nonce, unsigned char* mac);
48  static bool receive_hmac(yarp::os::InputStream* stream, unsigned char* nonce, unsigned char* mac);
49  static bool check_hmac(unsigned char* mac, unsigned char* mac_check);
50  static void fill_nonce(unsigned char* nonce);
51 
52  bool authentication_enabled;
53  HMAC_CONTEXT context;
54 };
55 
56 } // namespace impl
57 } // namespace os
58 } // namespace yarp
59 
60 #endif // YARP_OS_IMPL_AUTHHMAC_H
#define HMAC_CONTEXT
Definition: AuthHMAC.h:16
Simple specification of the minimum functions needed from input streams.
Definition: InputStream.h:26
Simple specification of the minimum functions needed from output streams.
Definition: OutputStream.h:22
3-way authentication via HMAC
Definition: AuthHMAC.h:31
virtual ~AuthHMAC()=default
Destructor.
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_impl_API
Definition: api.h:46