ykey.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * $Id: ykey.h 22965 2016-01-29 17:03:22Z seb $
4  *
5  * Declaration of standard key computations
6  *
7  * - - - - - - - - - License information: - - - - - - - - -
8  *
9  * Copyright (C) 2011 and beyond by Yoctopuce Sarl, Switzerland.
10  *
11  * Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual
12  * non-exclusive license to use, modify, copy and integrate this
13  * file into your software for the sole purpose of interfacing
14  * with Yoctopuce products.
15  *
16  * You may reproduce and distribute copies of this file in
17  * source or object form, as long as the sole purpose of this
18  * code is to interface with Yoctopuce products. You must retain
19  * this notice in the distributed source file.
20  *
21  * You should refer to Yoctopuce General Terms and Conditions
22  * for additional information regarding your rights and
23  * obligations.
24  *
25  * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
26  * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
27  * WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS
28  * FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO
29  * EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
30  * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
31  * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
32  * SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
33  * LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR
34  * CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE
35  * BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF
36  * WARRANTY, OR OTHERWISE.
37  *
38  *********************************************************************/
39 
40 #ifndef YKEY_H
41 #define YKEY_H
42 #include "ydef.h"
43 
44 void bin2str(char *to, const u8 *p, u16 len,u8 addnull);
45 
46 // HTTP digest authentication support
47 
48 #define HTTP_AUTH_MD5_SIZE 16
49 #define HTTP_AUTH_MD5_STRLEN (HTTP_AUTH_MD5_SIZE*2)
50 
51 void ComputeAuthHA1(u8 *buf, const char *user, const char *pass, const char *realm);
52 void ComputeAuthHA2(u8 *buf, const char *method, const char *url) ;
53 void ComputeAuthResponse(char *buf, const u8 * ha1, const char *nonce, const char *nc, const char *cnonce, const u8 *ha2);
54 int CheckWSAuth(u32 nonce, const u8 *ha1, const u8 *to_verify, u8 *out);
55 
56 // Parse a request header, return 0 if a valid WWW-Authenticate header and set args to corresponding fields
57 // - Request is patched in place to null-terminate each field.
58 // - If return value is 0, at least method,realm and qop are set to non-NULL value
59 // - qop is set to an empty string if not specified in thq authenticate header
60 int yParseWWWAuthenticate(char *replybuf, int replysize, char **method, char **realm, char **qop, char **nonce, char **opaque);
61 
62 // Fill in buf with a proper digest authorization header
63 void yDigestAuthorization(char *buf, int bufsize, const char *user, const char *realm, const u8 *ha1,
64  const char *nonce, const char *opaque, u32 *nc, const char *method, const char *uri);
65 
66 // Note: This API is designed for cooperative multitasking
67 // It is not multithread-safe
68 void yInitPsk(const char *pass, const char *ssid);
69 int yIterPsk(u8 *res, const char *ssid);
70 u8 *ySHA1(const char *text);
71 
72 // MD5 hash structures
73 #ifndef MICROCHIP_API
74 typedef struct {
75  u32 buf[4];
76  u32 bits[2];
77  union {
78  u8 in[64];
79  u32 in32[16];
80  };
81 } HASH_SUM;
82 
83 void MD5Initialize(HASH_SUM *theSum);
84 void MD5AddData(HASH_SUM *theSum, const u8* data, u32 len);
85 void MD5Calculate(HASH_SUM *theSum, u8* result);
86 #endif
87 
88 #endif
void ComputeAuthHA2(u8 *buf, const char *method, const char *url)
Definition: ykey.c:98
void ComputeAuthHA1(u8 *buf, const char *user, const char *pass, const char *realm)
Definition: ykey.c:77
Definition: ykey.h:74
int yParseWWWAuthenticate(char *replybuf, int replysize, char **method, char **realm, char **qop, char **nonce, char **opaque)
Definition: ykey.c:192
int CheckWSAuth(u32 nonce, const u8 *ha1, const u8 *to_verify, u8 *out)
Definition: ykey.c:158
void bin2str(char *to, const u8 *p, u16 len, u8 addnull)
Definition: ykey.c:63
void MD5AddData(HASH_SUM *theSum, const u8 *data, u32 len)
Definition: ykey.c:634
void yDigestAuthorization(char *buf, int bufsize, const char *user, const char *realm, const u8 *ha1, const char *nonce, const char *opaque, u32 *nc, const char *method, const char *uri)
Definition: ykey.c:269
u8 * ySHA1(const char *text)
Definition: ykey.c:425
int yIterPsk(u8 *res, const char *ssid)
Definition: ykey.c:463
void ComputeAuthResponse(char *buf, const u8 *ha1, const char *nonce, const char *nc, const char *cnonce, const u8 *ha2)
Definition: ykey.c:118
void yInitPsk(const char *pass, const char *ssid)
Definition: ykey.c:445
void MD5Calculate(HASH_SUM *theSum, u8 *result)
void MD5Initialize(HASH_SUM *theSum)
Definition: ykey.c:540


yoctopuce_altimeter
Author(s): Anja Sheppard
autogenerated on Mon Jun 10 2019 15:49:10