mirror of
https://github.com/qrtc/ffmpeg-dev-go.git
synced 2025-10-05 15:47:33 +08:00
2023-10-24 21:24:55 CST W43D2
This commit is contained in:
69
avutil_des.go
Normal file
69
avutil_des.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package ffmpeg
|
||||
|
||||
/*
|
||||
#include <libavutil/des.h>
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
// AVDES
|
||||
type AVDES C.struct_AVDES
|
||||
|
||||
// Custom: GetRoundKeys gets `AVDES.round_keys` value.
|
||||
func (d *AVDES) GetRoundKeys() (v [][]uint64) {
|
||||
for i := 0; i < 3; i++ {
|
||||
v = append(v, unsafe.Slice((*uint64)(&d.round_keys[i][0]), 16))
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Custom: SetRoundKeys sets `AVDES.round_keys` value.
|
||||
func (d *AVDES) SetRoundKeys(v [][]uint64) {
|
||||
for i := 0; i < FFMIN(len(v), 3); i++ {
|
||||
for j := 0; j < FFMIN(len(v[i]), 16); j++ {
|
||||
d.round_keys[i][j] = (C.uint64_t)(v[i][j])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Custom: GetRoundKeysAddr gets `AVDES.round_keys` address.
|
||||
func (d *AVDES) GetRoundKeysAddr() **uint64 {
|
||||
return (**uint64)(unsafe.Pointer(&d.round_keys))
|
||||
}
|
||||
|
||||
// Custom: GetTripleDes gets `AVDES.triple_des` value.
|
||||
func (d *AVDES) GetTripleDes() int32 {
|
||||
return (int32)(d.triple_des)
|
||||
}
|
||||
|
||||
// Custom: SetTripleDes sets `AVDES.triple_des` value.
|
||||
func (d *AVDES) SetTripleDes(v int32) {
|
||||
d.triple_des = (C.int)(v)
|
||||
}
|
||||
|
||||
// Custom: GetTripleDesAddr gets `AVDES.triple_des` address.
|
||||
func (d *AVDES) GetTripleDesAddr() *int32 {
|
||||
return (*int32)(&d.triple_des)
|
||||
}
|
||||
|
||||
// AvDesAlloc allocates an AVDES context.
|
||||
func AvDesAlloc() *AVDES {
|
||||
return (*AVDES)(C.av_des_alloc())
|
||||
}
|
||||
|
||||
// AvDesInit initializes an AVDES context.
|
||||
func AvDesInit(d *AVDES, key *uint8, keyBits, decrypt int32) int32 {
|
||||
return (int32)(C.av_des_init((*C.struct_AVDES)(d), (*C.uint8_t)(key),
|
||||
(C.int)(keyBits), (C.int)(decrypt)))
|
||||
}
|
||||
|
||||
// AvDesCrypt encrypts / decrypts using the DES algorithm.
|
||||
func AvDesCrypt(d *AVDES, dst, src *uint8, count int32, iv *uint8, decrypt int32) {
|
||||
C.av_des_crypt((*C.struct_AVDES)(d), (*C.uint8_t)(dst), (*C.uint8_t)(src),
|
||||
(C.int)(count), (*C.uint8_t)(iv), (C.int)(decrypt))
|
||||
}
|
||||
|
||||
// AvDesMac calculates CBC-MAC using the DES algorithm.
|
||||
func AvDesMac(d *AVDES, dst, src *uint8, count int32) {
|
||||
C.av_des_mac((*C.struct_AVDES)(d), (*C.uint8_t)(dst), (*C.uint8_t)(src), (C.int)(count))
|
||||
}
|
Reference in New Issue
Block a user