vitasdk
Documentation of the vitasdk
dmac5.h
Go to the documentation of this file.
1 
6 #ifndef _PSP2_DMAC5_H_
7 #define _PSP2_DMAC5_H_
8 
9 #include <vitasdk/build_utils.h>
10 #include <psp2/types.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 
17 typedef struct SceSblDmac5EncDecParam { // size is 0x18-bytes
18  const void *src; //<! The operation input buffer
19  void *dst; //<! The operation output buffer
20  SceSize length; //<! The src data length
21  const void *key; //<! The key data
22  SceSize keysize; //<! The key size in bits
23  void *iv; //<! The initialization vector
26 
27 typedef struct SceSblDmac5HashTransformContext { // size is 0x28-bytes
32 
33 typedef struct SceSblDmac5HashTransformParam { // size is 0x18-bytes
34  const void *src; //<! The operation input buffer
35  void *dst; //<! The operation output buffer
36  SceSize length; //<! The src data length
37  const void *key; //<! The key data
38  SceSize keysize; //<! The key size in bits
39  void *ctx; //<! SceSblDmac5HashTransformContext Or another context of size 0x10-bytes
42 
52 
53 
64 
65 
66 static inline int sceSblDmac5AesCbcEnc(const void *src, void *dst, SceSize length, const void *key, SceSize keysize, void *iv)
67 {
68  SceSblDmac5EncDecParam param = {.src = src, .dst = dst, .length = length, .key = key, .keysize = keysize, .iv = iv};
69 
70  return sceSblDmac5EncDec(
71  &param,
72  1 | 8 | (((keysize << 2) - 0x100) & 0x300)
73  );
74 }
75 
76 static inline int sceSblDmac5AesCbcDec(const void *src, void *dst, SceSize length, const void *key, SceSize keysize, void *iv)
77 {
78  SceSblDmac5EncDecParam param = {.src = src, .dst = dst, .length = length, .key = key, .keysize = keysize, .iv = iv};
79 
80  return sceSblDmac5EncDec(
81  &param,
82  2 | 8 | (((keysize << 2) - 0x100) & 0x300)
83  );
84 }
85 
86 static inline int sceSblDmac5AesCtrEnc(const void *src, void *dst, SceSize length, const void *key, SceSize keysize, void *iv)
87 {
88  SceSblDmac5EncDecParam param = {.src = src, .dst = dst, .length = length, .key = key, .keysize = keysize, .iv = iv};
89 
90  return sceSblDmac5EncDec(
91  &param,
92  1 | 0x20 | (((keysize << 2) - 0x100) & 0x300)
93  );
94 }
95 
96 static inline int sceSblDmac5AesCtrDec(const void *src, void *dst, SceSize length, const void *key, SceSize keysize, void *iv)
97 {
98  SceSblDmac5EncDecParam param = {.src = src, .dst = dst, .length = length, .key = key, .keysize = keysize, .iv = iv};
99 
100  return sceSblDmac5EncDec(
101  &param,
102  2 | 0x20 | (((keysize << 2) - 0x100) & 0x300)
103  );
104 }
105 
106 static inline int sceSblDmac5Sha256Digest(const void *src, void *dst, SceSize length)
107 {
109  SceSblDmac5HashTransformParam param = {.src = src, .dst = dst, .length = length, .key = NULL, .keysize = 0, .ctx = &ctx};
110 
111  ctx.state[0] = __builtin_bswap32(0x6a09e667);
112  ctx.state[1] = __builtin_bswap32(0xbb67ae85);
113  ctx.state[2] = __builtin_bswap32(0x3c6ef372);
114  ctx.state[3] = __builtin_bswap32(0xa54ff53a);
115  ctx.state[4] = __builtin_bswap32(0x510e527f);
116  ctx.state[5] = __builtin_bswap32(0x9b05688c);
117  ctx.state[6] = __builtin_bswap32(0x1f83d9ab);
118  ctx.state[7] = __builtin_bswap32(0x5be0cd19);
119  ctx.length = 0LL;
120 
122  &param,
123  3 | 0x10, 0x800
124  );
125 }
126 
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif /* _PSP2_DMAC5_H_ */
uint32_t length
Definition: bt.h:7
int sceSblDmac5EncDec(SceSblDmac5EncDecParam *param, SceUInt32 command)
Execute DMAC5 encdec command.
void * iv
Definition: dmac5.h:23
SceUInt64 length
Definition: dmac5.h:29
void * dst
Definition: dmac5.h:19
SceUInt32 state[8]
Definition: dmac5.h:28
int sceSblDmac5HashTransform(SceSblDmac5HashTransformParam *param, SceUInt32 command, SceUInt32 extra)
Execute DMAC5 hash transform command.
SceSize length
Definition: dmac5.h:20
void * ctx
Definition: dmac5.h:39
SceSize keysize
Definition: dmac5.h:38
VITASDK_BUILD_ASSERT_EQ(0x18, SceSblDmac5EncDecParam)
const void * src
Definition: dmac5.h:34
SceSize length
Definition: dmac5.h:36
void * dst
Definition: dmac5.h:35
const void * key
Definition: dmac5.h:37
SceSize keysize
Definition: dmac5.h:22
const void * key
Definition: dmac5.h:21
const void * src
Definition: dmac5.h:18
Definition: dmac5.h:17
Definition: dmac5.h:27
Definition: dmac5.h:33
unsigned int SceSize
Definition: types.h:56
uint64_t SceUInt64
Definition: types.h:51
uint32_t SceUInt32
Definition: types.h:45