aboutsummaryrefslogtreecommitdiff
path: root/xcode/OLMKit/OLMSAS.m
diff options
context:
space:
mode:
authormanuroe <manu@matrix.org>2019-04-08 18:48:09 +0200
committermanuroe <manu@matrix.org>2019-04-10 23:27:00 +0200
commit4057f59453d0276a7dbfeee284892c46786c156b (patch)
tree1f54e8202d6781cba47b771403ae2be6766992b2 /xcode/OLMKit/OLMSAS.m
parent5de295da3e5f9ae7e4de6cfe009e2d0ad4e6a08b (diff)
OLMKit: SAS: Added macLongKdf support
(cherry picked from commit 934d516eb35c488ee197e1bab78a4c81e3c8241d)
Diffstat (limited to 'xcode/OLMKit/OLMSAS.m')
-rw-r--r--xcode/OLMKit/OLMSAS.m34
1 files changed, 34 insertions, 0 deletions
diff --git a/xcode/OLMKit/OLMSAS.m b/xcode/OLMKit/OLMSAS.m
index d95f948..fed370b 100644
--- a/xcode/OLMKit/OLMSAS.m
+++ b/xcode/OLMKit/OLMSAS.m
@@ -137,4 +137,38 @@
return mac;
}
+- (NSString *)calculateMacLongKdf:(NSString *)input info:(NSString *)info error:(NSError *__autoreleasing _Nullable *)error {
+ NSMutableData *inputData = [input dataUsingEncoding:NSUTF8StringEncoding].mutableCopy;
+ NSData *infoData = [info dataUsingEncoding:NSUTF8StringEncoding];
+
+ size_t macLength = olm_sas_mac_length(olmSAS);
+ NSMutableData *macData = [NSMutableData dataWithLength:macLength];
+ if (!macData) {
+ return nil;
+ }
+
+ size_t result = olm_sas_calculate_mac_long_kdf(olmSAS,
+ inputData.mutableBytes, inputData.length,
+ infoData.bytes, infoData.length,
+ macData.mutableBytes, macLength);
+ if (result == olm_error()) {
+ const char *olm_error = olm_sas_last_error(olmSAS);
+ NSLog(@"[OLMSAS] calculateMacLongKdf: olm_sas_calculate_mac error: %s", olm_error);
+
+ NSString *errorString = [NSString stringWithUTF8String:olm_error];
+ if (error && olm_error && errorString) {
+ *error = [NSError errorWithDomain:OLMErrorDomain
+ code:0
+ userInfo:@{
+ NSLocalizedDescriptionKey: errorString,
+ NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"olm_sas_calculate_mac_long_kdf error: %@", errorString]
+ }];
+ }
+ return nil;
+ }
+
+ NSString *mac = [[NSString alloc] initWithData:macData encoding:NSUTF8StringEncoding];
+ return mac;
+}
+
@end