Motr  M0
cksum.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2021 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #pragma once
24 
25 #ifndef __MOTR_CKSUM_H__
26 #define __MOTR_CKSUM_H__
27 
28 #include "lib/vec.h"
29 #include "fid/fid.h"
30 #include "xcode/xcode_attr.h"
31 #ifndef __KERNEL__
32 #include <openssl/md5.h>
33 #endif
34 
35 
36 #define m0_cksum_print(buf, seg, dbuf, msg) \
37 do { \
38  struct m0_vec *vec = &(buf)->ov_vec; \
39  char *dst = (char *)(buf)->ov_buf[seg]; \
40  char *data = (char *)(dbuf)->ov_buf[seg]; \
41  M0_LOG(M0_DEBUG, msg " count[%d] = %"PRIu64 \
42  " cksum = %c%c data = %c%c", \
43  seg, vec->v_count[seg], dst[0], dst[1], data[0],data[1]); \
44 }while(0)
45 
46 
47 /*
48  * Macro calculates the size of padding required in a struct
49  * for byte alignment
50  * size - size of all structure members
51  * alignment - power of two, byte alignment
52  */
53 #define M0_CALC_PAD(size, alignment) ( size%alignment ? (((size/alignment + 1 ) * alignment) - size) : 0)
54 
55 
56 /* Constants for protection info type, max types supported is 8 */
57 enum
58 {
63 };
64 
66 
67  /* NO PI FLAG */
69  /* PI calculation for data unit 0 */
71  /* Skip PI final value calculation */
73 
74 };
75 
77 
78 struct m0_pi_hdr {
79  /* type of protection algorithm being used */
80  uint8_t pih_type : 8;
81  /*size of PI Structure in multiple of 32 bytes*/
82  uint8_t pih_size : 8;
83 };
84 
85 struct m0_md5_pi {
86 
87  /* header for protection info */
89 #ifndef __KERNEL__
90  /* protection value computed for the current data*/
91  unsigned char pimd5_value[MD5_DIGEST_LENGTH];
92  /* structure should be 32 byte aligned */
93  char pimd5_pad[M0_CALC_PAD((sizeof(struct m0_pi_hdr)+
94  MD5_DIGEST_LENGTH), 32)];
95 #endif
96 };
97 
99 
100  /* header for protection info */
102 #ifndef __KERNEL__
103  /*context of previous data unit, required for checksum computation */
104  unsigned char pimd5c_prev_context[sizeof(MD5_CTX)];
105  /* protection value computed for the current data unit.
106  * If seed is not provided then this checksum is
107  * calculated without seed.
108  */
109  unsigned char pimd5c_value[MD5_DIGEST_LENGTH];
110  /* structure should be 32 byte aligned */
111  char pi_md5c_pad[M0_CALC_PAD((sizeof(struct m0_pi_hdr)+
112  sizeof(MD5_CTX)+MD5_DIGEST_LENGTH), 32)];
113 #endif
114 };
115 
117  /* header for protection info */
119  /*pointer to access specific pi structure fields*/
120  void *pi_t_pi;
121 };
122 
123 /* seed values for calculating checksum */
124 struct m0_pi_seed {
126  /* offset within motr object */
128 };
129 
150 M0_INTERNAL int m0_calculate_md5_inc_context(
151  struct m0_md5_inc_context_pi *pi,
152  struct m0_pi_seed *seed,
153  struct m0_bufvec *bvec,
154  enum m0_pi_calc_flag flag,
155  unsigned char *curr_context,
156  unsigned char *pi_value_without_seed);
157 
162 M0_INTERNAL uint64_t m0_calculate_cksum_size(struct m0_generic_pi *pi);
163 
167 M0_INTERNAL uint64_t max_cksum_size(void);
168 
199  struct m0_pi_seed *seed,
200  struct m0_bufvec *bvec,
201  enum m0_pi_calc_flag flag,
202  unsigned char *curr_context,
203  unsigned char *pi_value_without_seed);
204 
205 
216  struct m0_pi_seed *seed,
217  struct m0_bufvec *bvec);
218 
219 #endif /* __MOTR_CKSUM_H__ */
unsigned char * curr_context[DATA_UNIT_COUNT]
unsigned char pimd5_value[MD5_DIGEST_LENGTH]
Definition: cksum.h:91
uint64_t m0_bindex_t
Definition: types.h:80
m0_bindex_t pis_data_unit_offset
Definition: cksum.h:127
char pi_md5c_pad[M0_CALC_PAD((sizeof(struct m0_pi_hdr)+sizeof(MD5_CTX)+MD5_DIGEST_LENGTH), 32)]
Definition: cksum.h:112
unsigned char pimd5c_value[MD5_DIGEST_LENGTH]
Definition: cksum.h:109
char pimd5_pad[M0_CALC_PAD((sizeof(struct m0_pi_hdr)+MD5_DIGEST_LENGTH), 32)]
Definition: cksum.h:94
struct m0_pi_hdr pimd5_hdr
Definition: cksum.h:88
M0_BASSERT(M0_PI_TYPE_MAX<=8)
static struct m0_bufvec bvec
Definition: xcode.c:169
m0_pi_calc_flag
Definition: cksum.h:65
M0_INTERNAL uint64_t m0_calculate_cksum_size(struct m0_generic_pi *pi)
Definition: cksum.c:146
struct m0_pdclust_instance pi
Definition: fd.c:107
void * pi_t_pi
Definition: cksum.h:120
#define M0_CALC_PAD(size, alignment)
Definition: cksum.h:53
struct m0_pi_hdr pimd5c_hdr
Definition: cksum.h:101
Definition: fid.h:38
uint8_t pih_size
Definition: cksum.h:82
struct m0_fid pis_obj_id
Definition: cksum.h:125
M0_INTERNAL uint64_t max_cksum_size(void)
Definition: cksum.c:162
static bool flag
Definition: nucleus.c:266
uint8_t pih_type
Definition: cksum.h:80
M0_INTERNAL int m0_calculate_md5_inc_context(struct m0_md5_inc_context_pi *pi, struct m0_pi_seed *seed, struct m0_bufvec *bvec, enum m0_pi_calc_flag flag, unsigned char *curr_context, unsigned char *pi_value_without_seed)
Definition: cksum.c:30
int m0_client_calculate_pi(struct m0_generic_pi *pi, struct m0_pi_seed *seed, struct m0_bufvec *bvec, enum m0_pi_calc_flag flag, unsigned char *curr_context, unsigned char *pi_value_without_seed)
Definition: cksum.c:168
bool m0_calc_verify_cksum_one_unit(struct m0_generic_pi *pi, struct m0_pi_seed *seed, struct m0_bufvec *bvec)
Definition: cksum.c:194
unsigned char pimd5c_prev_context[sizeof(MD5_CTX)]
Definition: cksum.h:104
struct m0_pi_hdr pi_hdr
Definition: cksum.h:118
Definition: vec.h:145